Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. @Slf4j
  2. @ControllerAdvice
  3. public class ExceptionControllerAdvice extends TwglControllerAdvice {
  4.  
  5. @ResponseBody
  6. @ExceptionHandler(Throwable.class)
  7. public RestExceptionDTO genericExceptionHandler(HttpServletResponse resp, Throwable ex) {
  8. log.error("API exception", ex);
  9. return buildExceptionDTO(resp, API_ERROR, ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  10. }
  11.  
  12. @ResponseBody
  13. @ExceptionHandler(AccessDeniedException.class)
  14. public RestExceptionDTO genericExceptionHandler(HttpServletResponse resp, AccessDeniedException ex) {
  15. return buildExceptionDTO(resp, ACCESS_DENIED_EXCEPTION, ex.getMessage(), HttpStatus.FORBIDDEN);
  16. }
  17.  
  18. @ResponseBody
  19. @ExceptionHandler(IllegalArgumentException.class)
  20. public RestExceptionDTO illegalArgumentExceptionHandler(HttpServletResponse resp, IllegalArgumentException ex) {
  21. return buildExceptionDTO(resp, API_ERROR, ex.getMessage(), HttpStatus.BAD_REQUEST);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement