From a23f4b202ea8a03aa81b1afb2dacc3248f5bfdd8 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <1179705413@qq.com> Date: Wed, 2 Apr 2025 08:19:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86404=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/CommonExceptionHandler.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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"; + } + /** * 处理数据校验异常 */