当前位置:   article > 正文

java 异常 过滤器_springboot如何处理过滤器filter中抛出的异常

com.hx.base.filter.exceptionloggerresponse

importcom.yzf.enterprise.market.common.constant.HttpStatus;importcom.yzf.enterprise.market.common.exception.BaseException;importcom.yzf.enterprise.market.common.exception.CustomException;importcom.yzf.enterprise.market.common.exception.DemoModeException;importcom.yzf.enterprise.market.common.utils.StringUtils;importcom.yzf.enterprise.market.framework.web.domain.AjaxResult;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.security.access.AccessDeniedException;importorg.springframework.security.authentication.AccountExpiredException;importorg.springframework.security.core.userdetails.UsernameNotFoundException;importorg.springframework.validation.BindException;importorg.springframework.web.bind.MethodArgumentNotValidException;importorg.springframework.web.bind.annotation.ExceptionHandler;importorg.springframework.web.bind.annotation.RestControllerAdvice;importorg.springframework.web.servlet.NoHandlerFoundException;/*** 全局异常处理器*/@RestControllerAdvicepublic classGlobalExceptionHandler {private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);/*** 基础异常*/@ExceptionHandler(BaseException.class)publicAjaxResult baseException(BaseException e) {returnAjaxResult.error(e.getMessage());

}/*** 业务异常*/@ExceptionHandler(CustomException.class)publicAjaxResult businessException(CustomException e) {if(StringUtils.isNull(e.getCode())) {returnAjaxResult.error(e.getMessage());

}returnAjaxResult.error(e.getCode(), e.getMessage());

}

@ExceptionHandler(NoHandlerFoundException.class)publicAjaxResult handlerNoFoundException(Exception e) {

log.error(e.getMessage(), e);return AjaxResult.error(HttpStatus.NOT_FOUND, "路径不存在,请检查路径是否正确");

}

@ExceptionHandler(AccessDeniedException.class)publicAjaxResult handleAuthorizationException(AccessDeniedException e) {

log.error(e.getMessage());return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权");

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/664758
推荐阅读
相关标签
  

闽ICP备14008679号