Is it possible to log response body of 4xx responses ?
tizba opened this issue · 2 comments
Discussed in #1575
Originally posted by tizba July 10, 2023
Hi,
Title basically.
Is it possible to log the response bodies of 4xx responses using the Spring Boot starter ?
It seems that it, by default, only logs the response bodies of 2xx responses.
Thanks in advance 😄
Baptiste
It seems that logbook doesn't work very well with ResponseStatusException
, because at the time the Filter is processing the response, the response output stream is empty. ResponseStatusException is converted to a body at a later point in time, after filters have finished processing the response.
One way to overcome this would be to ensure you have ProblemDetailsExceptionHandler
or any other child of ResponseEntityExceptionHandler
present in your spring context. In that case, error responses will be converted earlier into a ResponseEntity
and LogbookFilter will have access to the response body.
This issue has automatically been closed due to no activities. If the issue still exists in the latest version of the Logbook, please feel free to re-open it.