其他分享
首页 > 其他分享> > 统一异常处理 配置类

统一异常处理 配置类

作者:互联网

当用户身份认证失败时,会抛出UnauthorizedException,我们可以通过统一异常处理来处理该异常

@RestControllerAdvice
public class UserExceptionHandler {

   @ExceptionHandler(UnauthorizedException.class)
   @ResponseStatus(HttpStatus.UNAUTHORIZED)
   public ServerResponseVO UnAuthorizedExceptionHandler(UnauthorizedException e) {
       return ServerResponseVO.error(ServerResponseEnum.UNAUTHORIZED);
  }
}

 

标签:ServerResponseVO,UNAUTHORIZED,处理,配置,UnauthorizedException,异常,class,统一
来源: https://www.cnblogs.com/sudeng/p/15401661.html