添加全局ExceptionHandle以更优雅地处理JwtValidationException

This commit is contained in:
高子兴 2024-07-02 02:27:01 +08:00
parent 67c90b8f03
commit fd0cb2d345

View File

@ -0,0 +1,15 @@
package org.cmh.backend.Utils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(JwtValidationException.class)
public ResponseEntity<Object> handleJwtInvalidException(JwtValidationException ex) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
}