Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. @RestControllerAdvice
  2. public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
  3.  
  4.     @Override
  5.     protected ResponseEntity<Object> handleExceptionInternal(java.lang.Exception e, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
  6.         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(logOrSomeShit(e));
  7.     }
  8.  
  9.     @Override
  10.     protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
  11.         // Return HTTP 422: UNPROCESSABLE_ENTITY in case that a client tries to use an endpoint with incorrect arguments
  12.         return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).build();
  13.     }
  14.  
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement