forked from RyanGoodwill/backend
添加全局ExceptionHandle以更优雅地处理JwtValidationException
This commit is contained in:
parent
3641689cbb
commit
1d29684689
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user