-
Notifications
You must be signed in to change notification settings - Fork 4
Description
When the KittyCAD API returns a HTTP 4xx or 5xx error to the KittyCAD rust client, it triggers the Error::UnexpectedResponse
variant.
Generally our unit tests show the debug output of errors if they occur.
Unfortunately neither the debug nor display implementations for UnexpectedResponse are very helpful, because it doesn't show users the response body. Why not? Well, the UnexpectedResponse variant has one field, reqwest::Response
. But this variant doesn't actually show you the response body, because reading the response body consumes the response. This means if you wanted to put the response body in the Display
impl, it would consume the error object, so you'd only be able to read the error once.
Solution: the UnexpectedResponse variant should not contain a reqwest::Response
. Instead, when the variant is constructed, it should:
- Store useful data like headers and HTTP status
- read the response body as text
- Store the headers and response body in a field of the enum
This way the errors will be helpful, contain the response body, and don't consume data when read.