Skip to content

Commit 431ae05

Browse files
committed
feat: add MalformedJwtException handling
1 parent e1f8af4 commit 431ae05

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

rentplace/src/main/java/kattsyn/dev/rentplace/exceptions/GlobalExceptionHandler.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kattsyn.dev.rentplace.exceptions;
22

33
import io.jsonwebtoken.ExpiredJwtException;
4+
import io.jsonwebtoken.MalformedJwtException;
45
import jakarta.security.auth.message.AuthException;
56
import jakarta.servlet.http.HttpServletRequest;
67
import 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 = "";

0 commit comments

Comments
 (0)