package com.ym.mec.collectfee.common.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class BasicControllerAdvice extends BaseController {

	private final static Logger logger = LoggerFactory.getLogger(BasicControllerAdvice.class);

	/**
	 * 处理一般异常
	 * 
	 * @param ex
	 * @param request
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public HttpResponseResult handleException(Exception ex, HttpServletRequest request) {
		Throwable e = ExceptionUtils.getRootCause(ex);
		if (e == null) {
			e = ex;
		}

		logger.error("System Error", e);
		return failed("系统内部错误："+e.getMessage());
	}

}
