zoukankan      html  css  js  c++  java
  • SpringBoot全局异常处理

    全局异常处理

    @Slf4j
    @ControllerAdvice
    public class ControllerExceptionHandler {
    
    
        @ExceptionHandler(value = Exception.class)
        @ResponseBody
        public ResponseResult<String> defaultErrorHandler(HttpServletRequest request, Exception exception){
            log.error(ControllerLog.getLogPrefix()+"Exception: {}"+exception);
            return handleErrorInfo(exception.getMessage());
        }
    
        @ExceptionHandler(CheckException.class)
        @ResponseBody
        public ResponseResult<String> checkExceptionHandler(HttpServletRequest request, CheckException exception){
            return handleErrorInfo(exception.getMessage());
        }
    
        private ResponseResult<String> handleErrorInfo(String message) {
            ResponseResult<String> responseEntity = new ResponseResult<>();
            responseEntity.setMessage(message);
            responseEntity.setCode(ResponseResult.ERROR);
            responseEntity.setData(message);
            ControllerLog.destoryThreadLocal();
            return responseEntity;
        }
    }
  • 相关阅读:
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业03
    C语言I博客作业02
    作业01
    java ui 点点记
    eclipse修改workspace目录
    postgres恢复
    JDK1.4和JDK1.5以及1.6
  • 原文地址:https://www.cnblogs.com/pxblog/p/13813217.html
Copyright © 2011-2022 走看看