package com.qxueyou.scc.base.handler;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.servlet.ModelAndView;
|
|
/**
|
* Spring MVC 异常处理类
|
* @author 德虎
|
*
|
*/
|
@ControllerAdvice
|
public class QXueyouExceptionHandler {
|
|
private static Logger log = LogManager.getLogger("QXueyouExceptionHandler");
|
|
@ExceptionHandler(value = Exception.class)
|
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e)
|
throws Exception {
|
|
long exepCode = System.currentTimeMillis();
|
log.error(req.getRequestURL() + ",诊断代码:" + exepCode + ":" + e.getMessage(), e);
|
|
if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
|
throw e;
|
}
|
|
ModelAndView mav = new ModelAndView();
|
mav.addObject("exepCode", String.valueOf(exepCode));
|
mav.setViewName("error");
|
|
return mav;
|
}
|
|
}
|