reqwest
reqwest copied to clipboard
Keep body around in `Error` when JSON decoding fails
- Sometimes you want to inspect the JSON data that failed to parse.
If desired, it is possible to facilitate this by using .bytes() or .text() instead of .json(), and then doing serde_json::from_slice/from_str as appropriate. If that fails, the Bytes/String structure will be available to you.
If desired, it is possible to facilitate this by using
.bytes()or.text()instead of.json(), and then doingserde_json::from_slice/from_stras appropriate. If that fails, theBytes/Stringstructure will be available to you.
yes, that's what I am basically doing. Actually, I wrote a RequestExt trait that adds a json_with_error_logging method that will error! out the failed JSON.
If the failed JSON body would accessible in the error Result, I could instead decide what to do with the error (whether to log it or not), later on in the error handler.