From f69b67cbd2e9c20fb79df9a463c44480ff044862 Mon Sep 17 00:00:00 2001 From: Ghost_chu Date: Tue, 8 Oct 2024 14:54:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=B0=86=20404=20=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=A7=A3=E9=87=8A=E4=B8=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../btn/sparkle/controller/GlobalExceptionHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/ghostchu/btn/sparkle/controller/GlobalExceptionHandler.java b/src/main/java/com/ghostchu/btn/sparkle/controller/GlobalExceptionHandler.java index 9c59463..bc80d0a 100644 --- a/src/main/java/com/ghostchu/btn/sparkle/controller/GlobalExceptionHandler.java +++ b/src/main/java/com/ghostchu/btn/sparkle/controller/GlobalExceptionHandler.java @@ -9,6 +9,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.resource.NoResourceFoundException; @RestControllerAdvice @Slf4j @@ -25,6 +26,12 @@ public ResponseEntity> userBannedException(UserBannedException e){ public ResponseEntity> businessExceptionHandler(NotLoginException e){ return ResponseEntity.status(403).body(new StdResp<>(false,"未登录或会话已过期,请转到首页登录", null)); } + + @ExceptionHandler(NoResourceFoundException.class) + public ResponseEntity> noResourceFoundException(Exception e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(new StdResp<>(false, "404 Not Found - 资源未找到", null)); + } @ExceptionHandler(Exception.class) public ResponseEntity> jvmExceptionHandler(Exception e){ log.error("Unexpected exception", e);