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) {