コード例 #1
0
  /**
   * 没有权限 异常
   *
   * <p>后续根据不同的需求定制即可
   */
  @ExceptionHandler({UnauthorizedException.class})
  @ResponseStatus(HttpStatus.UNAUTHORIZED)
  public ModelAndView processUnauthenticatedException(
      NativeWebRequest request, UnauthorizedException e) {
    LogUtils.logError("用户权限验证失败", e);

    ExceptionResponse exceptionResponse = ExceptionResponse.from(e);

    ModelAndView mv = new ModelAndView();
    mv.addObject("error", exceptionResponse);
    mv.setViewName("error/exception");

    return mv;
  }