2024-01-20 20:56:02 +07:00
|
|
|
package com.hakimfauzi23.boilerplatespringsecurity.jwt.advice;
|
2024-01-03 17:17:42 +07:00
|
|
|
|
2024-01-20 20:56:02 +07:00
|
|
|
import com.hakimfauzi23.boilerplatespringsecurity.jwt.exception.ErrorMessage;
|
|
|
|
|
import com.hakimfauzi23.boilerplatespringsecurity.jwt.exception.TokenRefreshException;
|
2024-01-03 17:17:42 +07:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
|
import org.springframework.web.context.request.WebRequest;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
@RestControllerAdvice
|
|
|
|
|
public class TokenControllerAdvice {
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler(value = TokenRefreshException.class)
|
|
|
|
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
|
|
|
|
public ErrorMessage handleTokenRefreshException(TokenRefreshException ex, WebRequest request) {
|
|
|
|
|
return new ErrorMessage(
|
|
|
|
|
HttpStatus.FORBIDDEN.value(),
|
|
|
|
|
new Date(),
|
|
|
|
|
ex.getMessage(),
|
|
|
|
|
request.getDescription(false)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|