Skip to content

Commit

Permalink
Warn about ResponseEntity-ProblemDetail status mismatch
Browse files Browse the repository at this point in the history
Closes gh-29378
  • Loading branch information
rstoyanchev committed Nov 1, 2022
1 parent 921eead commit 5ef3aab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ else if (returnValue instanceof HttpHeaders) {
URI path = URI.create(exchange.getRequest().getPath().value());
detail.setInstance(path);
}
if (logger.isWarnEnabled() && httpEntity instanceof ResponseEntity<?> responseEntity) {
if (responseEntity.getStatusCode().value() != detail.getStatus()) {
logger.warn(actualParameter.getExecutable().toGenericString() +
" returned ResponseEntity: " + responseEntity + ", but its status" +
" doesn't match the ProblemDetail status: " + detail.getStatus());
}
}
}

if (httpEntity instanceof ResponseEntity<?> responseEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ else if (returnValue instanceof ProblemDetail detail) {
URI path = URI.create(inputMessage.getServletRequest().getRequestURI());
detail.setInstance(path);
}
if (logger.isWarnEnabled() && httpEntity instanceof ResponseEntity<?> responseEntity) {
if (responseEntity.getStatusCode().value() != detail.getStatus()) {
logger.warn(returnType.getExecutable().toGenericString() +
" returned ResponseEntity: " + responseEntity + ", but its status" +
" doesn't match the ProblemDetail status: " + detail.getStatus());
}
}
}

HttpHeaders outputHeaders = outputMessage.getHeaders();
Expand Down

0 comments on commit 5ef3aab

Please sign in to comment.