fix(api): malformed ?from/?to returns 400 instead of 500

Extends the existing ApiExceptionHandler @RestControllerAdvice to map
DateTimeParseException and IllegalArgumentException to 400 Bad Request.
Logs and agent-events endpoints both parse ISO-8601 query params and
previously leaked parse failures as internal server errors. All
IllegalArgumentException throw sites in production code are
input-validation usages (slug validation, containerConfig validation,
cursor decoding), so mapping to 400 is correct across the board.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-17 13:14:18 +02:00
parent f1c5a95f12
commit a0a0635ddd

View File

@@ -6,6 +6,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.server.ResponseStatusException;
import java.time.format.DateTimeParseException;
/**
* Global exception handler that ensures error responses use the typed {@link ErrorResponse} schema.
*/
@@ -18,4 +20,11 @@ public class ApiExceptionHandler {
return ResponseEntity.status(ex.getStatusCode())
.body(new ErrorResponse(reason != null ? reason : "Unknown error"));
}
@ExceptionHandler({DateTimeParseException.class, IllegalArgumentException.class})
public ResponseEntity<ErrorResponse> handleBadRequest(Exception ex) {
String msg = ex.getMessage();
return ResponseEntity.badRequest()
.body(new ErrorResponse(msg != null ? msg : "Bad request"));
}
}