diff --git a/src/main/java/io/github/xxyopen/novel/core/common/exception/CommonExceptionHandler.java b/src/main/java/io/github/xxyopen/novel/core/common/exception/CommonExceptionHandler.java index 3104c82..23ba97c 100644 --- a/src/main/java/io/github/xxyopen/novel/core/common/exception/CommonExceptionHandler.java +++ b/src/main/java/io/github/xxyopen/novel/core/common/exception/CommonExceptionHandler.java @@ -3,9 +3,12 @@ package io.github.xxyopen.novel.core.common.exception; import io.github.xxyopen.novel.core.common.constant.ErrorCodeEnum; import io.github.xxyopen.novel.core.common.resp.RestResp; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; import org.springframework.validation.BindException; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.resource.NoResourceFoundException; /** * 通用的异常处理器 @@ -17,6 +20,15 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; @RestControllerAdvice public class CommonExceptionHandler { + /** + * 处理404异常 + */ + @ExceptionHandler(NoResourceFoundException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public String handlerNotFound() { + return "404"; + } + /** * 处理数据校验异常 */