fix: report history storage availability clearly

This commit is contained in:
lingniu
2026-06-29 14:35:13 +08:00
parent 2273d72e95
commit a66cfe1532
2 changed files with 56 additions and 0 deletions

View File

@@ -8,7 +8,9 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.resource.NoResourceFoundException;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeParseException;
@@ -69,6 +71,18 @@ public final class ApiExceptionHandler {
return error(HttpStatus.BAD_REQUEST, "invalid date/time parameter: " + ex.getParsedString(), request);
}
@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<ApiError> noResource(NoResourceFoundException ex,
HttpServletRequest request) {
return error(HttpStatus.NOT_FOUND, "resource not found: " + request.getRequestURI(), request);
}
@ExceptionHandler(IOException.class)
public ResponseEntity<ApiError> io(IOException ex,
HttpServletRequest request) {
return error(HttpStatus.SERVICE_UNAVAILABLE, safeMessage(ex, "history storage unavailable"), request);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiError> generic(Exception ex,
HttpServletRequest request) {