| 12345678910111213141516171819202122232425262728 |
- package com.steerinfo.dil.config;
- import com.steerinfo.framework.controller.RESTfulResult;
- import org.apache.log4j.Logger;
- import org.springframework.web.bind.annotation.ControllerAdvice;
- import org.springframework.web.bind.annotation.ExceptionHandler;
- import org.springframework.web.bind.annotation.ResponseBody;
- import java.text.ParseException;
- @ControllerAdvice
- public class WebExceptionHandler {
- static final Logger log = Logger.getLogger(WebExceptionHandler.class);
- @ExceptionHandler(value = Exception.class)
- @ResponseBody
- public RESTfulResult exceptionHandler(Exception e) {
- log.error("全局异常捕获:" + e);
- e.printStackTrace();
- if (e instanceof NullPointerException) {
- return new RESTfulResult("500", "操作失败:缺乏必要参数!", e);
- } else if (e instanceof ParseException) {
- return new RESTfulResult("500", "操作失败:格式转换异常!", e);
- }
- return new RESTfulResult("500", "操作失败:" + e.getMessage(), e);
- }
- }
|