如何在@exeptionhandler和响应体中处理多个异常?

时间:2015-07-02 08:07:53

标签: spring spring-security exceptionhandler spring-web

我应该使用org.springframework.security.access.AccessDeniedException作为参数创建一个额外的方法吗?

@ControllerAdvice
public class AccessDeniedExceptionAdvice {

    private final Logger log = LoggerFactory.getLogger(getClass());
    @Autowired
    private ErrorResponseMapperService errorResponseMapper;

    @ExceptionHandler({ com.mycomp.myapp.platform.common.exception.AccessDeniedException.class
                      , org.springframework.security.access.AccessDeniedException.class }) // <-- Here i have added an extra exeption
    @ResponseStatus(value = HttpStatus.FORBIDDEN)
    @ResponseBody
    public ErrorResponseDto accessDenied(com.mycomp.myapp.platform.common.exception.AccessDeniedException.class ex) {
        log.error("Access denied", ex);
        return errorResponseMapper.createErrorReponseDto(null, "Access Denied",
                MyAppErrorCodesEnumDto.MY_APP_UNAUTHORIZED_EXCEPTION);
    }
}

0 个答案:

没有答案