feat: 优化404错误返回

This commit is contained in:
曹鹏飞 2025-09-25 11:54:21 +08:00
parent 67623100b0
commit d679fd47bd
1 changed files with 8 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
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;
import java.util.ArrayList;
import java.util.List;
@ -66,4 +67,11 @@ public class GlobalRestControllerAdvice {
public String handleNotLoginException(NotLoginException e) {
return "请重新登录";
}
@ExceptionHandler(NoResourceFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ApiResult<Void> handleNoResourceFoundException(NoResourceFoundException ex) {
log.error("请求的地址无效: ", ex);
return ApiResult.error(STATE.BusinessError, "请求的地址无效:" + ex.getResourcePath());
}
}