From 3f15ae0743cfdb972efc7bd927d426205e6cc1a1 Mon Sep 17 00:00:00 2001 From: 05412 Date: Fri, 2 Aug 2024 16:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/dev/surl/surl/handler/DefaultExceptionHandler.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/surl/surl/handler/DefaultExceptionHandler.kt b/src/main/java/dev/surl/surl/handler/DefaultExceptionHandler.kt index ddca2c9..b0398fd 100644 --- a/src/main/java/dev/surl/surl/handler/DefaultExceptionHandler.kt +++ b/src/main/java/dev/surl/surl/handler/DefaultExceptionHandler.kt @@ -9,6 +9,7 @@ import org.springframework.http.HttpStatus import org.springframework.http.HttpStatusCode import org.springframework.http.ResponseEntity import org.springframework.http.converter.HttpMessageNotReadableException +import org.springframework.security.core.userdetails.UsernameNotFoundException import org.springframework.validation.method.MethodValidationException import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ControllerAdvice @@ -98,7 +99,7 @@ class DefaultExceptionHandler : ResponseEntityExceptionHandler() { return ResponseEntity(Msg(code = -1, msg = ex.message ?: "unknown validation error"), HttpStatus.BAD_REQUEST) } - @ExceptionHandler(value = [UnauthorizedException::class]) + @ExceptionHandler(value = [UnauthorizedException::class, UsernameNotFoundException::class]) fun handleUnauthorizedException(ex: Exception): ResponseEntity> { return ResponseEntity(Msg(code = -1, msg = ex.message ?: "unauthorized"), HttpStatus.UNAUTHORIZED) }