Skip to content
This repository was archived by the owner on Nov 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,20 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
.body(problem);
}

/** Framework MVC errors (missing param, unreadable body, ...) also carry the correlation id. */
/**
* Framework MVC errors (missing param, unreadable body, ...) also carry the correlation id.
* Some arrive with a null body (a missing query parameter, for one) and the superclass builds
* the ProblemDetail itself, so the id is added to the body it returns.
*/
@Override
protected ResponseEntity<Object> handleExceptionInternal(
Exception ex, Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) {
if (body instanceof ProblemDetail problem) {
ResponseEntity<Object> response =
super.handleExceptionInternal(ex, body, headers, statusCode, request);
if (response != null && response.getBody() instanceof ProblemDetail problem) {
withCorrelation(problem);
}
return super.handleExceptionInternal(ex, body, headers, statusCode, request);
return response;
}

static ProblemDetail withCorrelation(ProblemDetail problem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,20 @@ void create_withoutBearer_returns401() throws Exception {

verify(interactionService, never()).create(any(), any());
}

/** Missing customerId is a framework 400; it carries the request correlation id like the rest. */
@Test
void list_missingCustomerId_shouldCarryTheRequestCorrelationId() throws Exception {
mockMvc
.perform(
get("/api/v1/interactions")
.header("Authorization", bearer)
.header("X-Correlation-Id", "missing-param-001"))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_PROBLEM_JSON))
.andExpect(jsonPath("$.status").value(400))
.andExpect(jsonPath("$.correlationId").value("missing-param-001"));

verify(interactionService, never()).list(any());
}
}
Loading