I've been stuck on this task for quite a while. It seems simple, whenever an error happens during a RestClient request, I want to log both the request and response data + body for debugging purposes.
However, RestClient only seems to support logging request data. The response body does not appear in cases of non-HTTP errors, such as JSON deserialization mismatches, even though the body was received successfully and is simply in an unexpected format.
Right now, I have many requests made through RestClient where I receive the response as a String, manually parse it into JSON, and then handle errors myself. This approach is becoming extremly annoying.
Is there a way to catch both HTTP errors and JSON parsing/deserialization errors in one place and log the full request and response when using RestClient?
The same issue seems to apply to WebClient as well, since, to my knowledge, it also lacks proper handlers for body parsing/deserialization errors.
Note: I don't want to log all requests and responses — only those where an error occurs.