| | |
| | | import org.springframework.web.bind.annotation.ControllerAdvice; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.List; |
| | |
| | | * Copyright (C), 2020-2024, 武汉思维跳跃科技有限公司 |
| | | * @date 2021/12/25 9:45 |
| | | */ |
| | | @ControllerAdvice |
| | | @RestControllerAdvice |
| | | public class ExceptionHandle { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(ExceptionHandle.class); |
| | | /** 公司项目的包结构,用于缩短错误日志的长度 */ |
| | | /** |
| | | * 公司项目的包结构,用于缩短错误日志的长度 |
| | | */ |
| | | private final static String COMPANY_PACKAGE = "com.ycl.jxkg."; |
| | | |
| | | /** |
| | |
| | | String errMsg = String.format("系统异常-%s", e.getMessage()); |
| | | this.printExceptionLocation(e, request, errMsg); |
| | | return new Result<>(SystemCode.InnerError.getCode(), SystemCode.InnerError.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * Handler rest response. |
| | | * |
| | | * @param e the e |
| | | * @return the rest response |
| | | */ |
| | | @ExceptionHandler(RuntimeException.class) |
| | | @ResponseBody |
| | | public Result handler(RuntimeException e, HttpServletRequest request) { |
| | | String errMsg = String.format("系统异常-%s", e.getMessage()); |
| | | this.printExceptionLocation(e, request, errMsg); |
| | | return new Result<>(SystemCode.InnerError.getCode(), e.getMessage()); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * 打印异常出现位置 |
| | | * |
| | | * @param e |
| | | */ |
| | | private void printExceptionLocation(Throwable e, HttpServletRequest request, String errMsg) { |