package com.sczx.sync.exception; import com.sczx.sync.common.Result; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; /** * @author zhangli */ @Slf4j @ControllerAdvice public class GlobalExceptionHandler { /** * 处理自定义的业务异常 * * @param req * @param e * @return */ @ExceptionHandler(value = BizException.class) @ResponseBody public Result bizExceptionHandler(HttpServletRequest req, BizException e) { log.warn("发生业务异常!原因是:{}", e.getErrorMsg(), e); return Result.fail(e.getErrorCode(), e.getErrorMsg()); } @ExceptionHandler(value = InnerException.class) @ResponseBody public Result innerExceptionHandler(HttpServletRequest req, InnerException e) { log.error("发生服务内部异常!原因是:{}", e.getErrorMsg(), e); return Result.fail(e.getErrorCode(), e.getErrorMsg()); } @ExceptionHandler(value = Exception.class) @ResponseBody public Result exceptionHandler(HttpServletRequest req, Exception e) { log.error("意料外异常!原因是:{}", e.getMessage(), e); return Result.fail("99999", "系统内部异常"); } }