Skip to content

Commit f08cab2

Browse files
committed
(TP-111) feat: add ExpiredJwtException handling
1 parent 78c28b3 commit f08cab2

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

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

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

3+
import io.jsonwebtoken.ExpiredJwtException;
34
import jakarta.security.auth.message.AuthException;
45
import jakarta.servlet.http.HttpServletRequest;
56
import kattsyn.dev.rentplace.dtos.ErrorResponse;
@@ -55,6 +56,17 @@ public ResponseEntity<ErrorResponse> handleValidationExceptions(AuthException ex
5556
return new ResponseEntity<>(response, HttpStatus.UNAUTHORIZED);
5657
}
5758

59+
@ExceptionHandler(ExpiredJwtException.class)
60+
public ResponseEntity<ErrorResponse> handleValidationExceptions(ExpiredJwtException ex, WebRequest request) {
61+
ErrorResponse response = new ErrorResponse(
62+
HttpStatus.UNAUTHORIZED.value(),
63+
"JSON WEB TOKEN EXPIRED",
64+
ex.getMessage(),
65+
request.getDescription(false).replace("uri=", "")
66+
);
67+
return new ResponseEntity<>(response, HttpStatus.UNAUTHORIZED);
68+
}
69+
5870
@ExceptionHandler(Exception.class)
5971
public ResponseEntity<ErrorResponse> handleAllExceptions(Exception ex, WebRequest request) {
6072
String path = "";

0 commit comments

Comments
 (0)