fix: log deserialization failures on log ingestion endpoint
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m23s
CI / docker (push) Successful in 1m4s
CI / deploy (push) Successful in 41s
CI / deploy-feature (push) Has been skipped

Spring's default handler silently returns 400 for malformed payloads
with no server-side log. Added @ExceptionHandler to catch and WARN with
the agent instance ID and root cause message.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-12 15:33:57 +02:00
parent 2d3817b296
commit d161ad38a8

View File

@@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -94,6 +96,14 @@ public class LogIngestionController {
return ResponseEntity.accepted().build();
}
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<Void> handleDeserializationError(HttpMessageNotReadableException ex) {
String instanceId = extractAgentId();
log.warn("Log ingestion from instance={}: failed to deserialize request body: {}",
instanceId != null ? instanceId : "unknown", ex.getMostSpecificCause().getMessage());
return ResponseEntity.badRequest().build();
}
private String extractAgentId() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
return auth != null ? auth.getName() : null;