Skip to content

Commit 5ef3aab

Browse files
committed
Warn about ResponseEntity-ProblemDetail status mismatch
Closes gh-29378
1 parent 921eead commit 5ef3aab

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ else if (returnValue instanceof HttpHeaders) {
159159
URI path = URI.create(exchange.getRequest().getPath().value());
160160
detail.setInstance(path);
161161
}
162+
if (logger.isWarnEnabled() && httpEntity instanceof ResponseEntity<?> responseEntity) {
163+
if (responseEntity.getStatusCode().value() != detail.getStatus()) {
164+
logger.warn(actualParameter.getExecutable().toGenericString() +
165+
" returned ResponseEntity: " + responseEntity + ", but its status" +
166+
" doesn't match the ProblemDetail status: " + detail.getStatus());
167+
}
168+
}
162169
}
163170

164171
if (httpEntity instanceof ResponseEntity<?> responseEntity) {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ else if (returnValue instanceof ProblemDetail detail) {
197197
URI path = URI.create(inputMessage.getServletRequest().getRequestURI());
198198
detail.setInstance(path);
199199
}
200+
if (logger.isWarnEnabled() && httpEntity instanceof ResponseEntity<?> responseEntity) {
201+
if (responseEntity.getStatusCode().value() != detail.getStatus()) {
202+
logger.warn(returnType.getExecutable().toGenericString() +
203+
" returned ResponseEntity: " + responseEntity + ", but its status" +
204+
" doesn't match the ProblemDetail status: " + detail.getStatus());
205+
}
206+
}
200207
}
201208

202209
HttpHeaders outputHeaders = outputMessage.getHeaders();

0 commit comments

Comments
 (0)