Skip to content

UnexpectedResponse should grab response body #194

@adamchalmers

Description

@adamchalmers

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:

  1. Store useful data like headers and HTTP status
  2. read the response body as text
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions