| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package com.xcgl.weixin.base;
- import com.xcgl.weixin.entity.WXAjaxJson;
- 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;
- /**
- * 全局Controller层异常处理类
- */
- @ControllerAdvice
- public class ApiExceptionResolver {
- private static final Logger LOG = LoggerFactory.getLogger(ApiExceptionResolver.class);
- // /**
- // * 处理所有不可知异常
- // *
- // * @param e 异常
- // * @return json结果
- // */
- // @ExceptionHandler(Exception.class)
- // @ResponseBody
- // public Result handleException(Exception e) {
- // // 打印异常堆栈信息
- // LOG.error(e.getMessage(), e);
- // return Result.error(ResultEnum.ERROR.getCode(), e.getMessage());
- // }
- /**
- * 处理所有业务异常
- *
- * @param e 业务异常
- * @return json结果
- */
- @ExceptionHandler(ApiException.class)
- @ResponseBody
- public WXAjaxJson handleOpdRuntimeException(ApiException e) {
- // 不打印异常堆栈信息
- LOG.error(e.getMessage());
- return WXAjaxJson.error(e.getCode(), e.getMessage());
- }
- }
|