File tree Expand file tree Collapse file tree
rentplace/src/main/java/kattsyn/dev/rentplace/exceptions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package kattsyn .dev .rentplace .exceptions ;
22
33import io .jsonwebtoken .ExpiredJwtException ;
4+ import io .jsonwebtoken .MalformedJwtException ;
45import jakarta .security .auth .message .AuthException ;
56import jakarta .servlet .http .HttpServletRequest ;
67import kattsyn .dev .rentplace .dtos .responses .ErrorResponse ;
@@ -67,6 +68,18 @@ public ResponseEntity<ErrorResponse> handleValidationExceptions(ExpiredJwtExcept
6768 return new ResponseEntity <>(response , HttpStatus .UNAUTHORIZED );
6869 }
6970
71+
72+ @ ExceptionHandler (MalformedJwtException .class )
73+ public ResponseEntity <ErrorResponse > handleValidationExceptions (MalformedJwtException ex , WebRequest request ) {
74+ ErrorResponse response = new ErrorResponse (
75+ HttpStatus .UNAUTHORIZED .value (),
76+ "JWT WAS NOT CORRECTLY CONSTRUCTED AND SHOULD BE REJECTED" ,
77+ ex .getMessage (),
78+ request .getDescription (false ).replace ("uri=" , "" )
79+ );
80+ return new ResponseEntity <>(response , HttpStatus .UNAUTHORIZED );
81+ }
82+
7083 @ ExceptionHandler (Exception .class )
7184 public ResponseEntity <ErrorResponse > handleAllExceptions (Exception ex , WebRequest request ) {
7285 String path = "" ;
You can’t perform that action at this time.
0 commit comments