feat: 处理404异常

This commit is contained in:
xiongxiaoyang 2025-04-02 08:19:20 +08:00
parent cd3a7206a9
commit a23f4b202e

View File

@ -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";
}
/**
* 处理数据校验异常
*/