fix token issues

This commit is contained in:
Krrish Ghimire
2026-07-06 00:58:11 +05:45
parent 874eb33678
commit f70fe81432
6 changed files with 26 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
package com.krrishg.config;
import io.jsonwebtoken.JwtException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
@@ -16,6 +17,11 @@ public class GlobalExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(JwtException.class)
public ProblemDetail handleJwtException(JwtException ex) {
return ProblemDetail.forStatusAndDetail(HttpStatus.UNAUTHORIZED, ex.getMessage());
}
@ExceptionHandler(IllegalArgumentException.class)
public ProblemDetail handleBadRequest(IllegalArgumentException ex) {
return ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, ex.getMessage());

View File

@@ -134,9 +134,6 @@ public class SecurityConfig {
} catch (Exception e) {
org.springframework.security.core.context.SecurityContextHolder
.clearContext();
response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
"Invalid or expired token");
return;
}
}