fix:favicon.ico

This commit is contained in:
waner
2026-05-06 09:47:19 +08:00
parent 61280718dc
commit c259e6bd2b
3 changed files with 46 additions and 0 deletions
@@ -5,6 +5,7 @@ public enum ErrorCode {
UNAUTHORIZED(4010, "未认证或认证失败"),
SESSION_INVALID(4011, "会话无效"),
FORBIDDEN(4030, "无权限访问"),
NOT_FOUND(4040, "资源不存在"),
VALIDATE_FAILED(4001, "参数校验失败"),
CONFLICT(4090, "数据冲突"),
BIZ_ERROR(5001, "业务处理异常"),
@@ -14,6 +14,7 @@ import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartException;
@@ -79,6 +80,16 @@ public class GlobalExceptionHandler {
.withPath(request.getRequestURI()));
}
@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<ApiResponse<Void>> handleNoResourceFound(NoResourceFoundException ex, HttpServletRequest request) {
if ("/favicon.ico".equals(request.getRequestURI())) {
return ResponseEntity.noContent().build();
}
return response(HttpStatus.NOT_FOUND,
ApiResponse.fail(ErrorCode.NOT_FOUND.getCode(), "resource not found")
.withPath(request.getRequestURI()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<Void>> handleException(Exception ex, HttpServletRequest request) {
log.error("Unhandled exception", ex);