From 70aec18d52dddd66953528d2353f806c88a05f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Sat, 6 Apr 2024 14:47:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=BF=94=E5=9B=9E404=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maku/framework/common/exception/ServerExceptionHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/maku-framework/src/main/java/net/maku/framework/common/exception/ServerExceptionHandler.java b/maku-framework/src/main/java/net/maku/framework/common/exception/ServerExceptionHandler.java index f64004f..a103037 100644 --- a/maku-framework/src/main/java/net/maku/framework/common/exception/ServerExceptionHandler.java +++ b/maku-framework/src/main/java/net/maku/framework/common/exception/ServerExceptionHandler.java @@ -2,11 +2,14 @@ package net.maku.framework.common.exception; import lombok.extern.slf4j.Slf4j; import net.maku.framework.common.utils.Result; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindException; import org.springframework.validation.FieldError; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.resource.NoResourceFoundException; /** @@ -37,6 +40,11 @@ public class ServerExceptionHandler { return Result.error(fieldError.getDefaultMessage()); } + @ExceptionHandler(NoResourceFoundException.class) + public ResponseEntity handleResourceNotFoundException(NoResourceFoundException e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("404 Not Found: " + e.getResourcePath()); + } + @ExceptionHandler(AccessDeniedException.class) public Result handleAccessDeniedException(Exception ex) {