Skip to content

Propagate request's response to be able to read status codes, and more #2317

Open
@konsalex

Description

@konsalex

openapi-fetch version

openapi-fetch

Description

Currently in the docs it says:

onError does not handle error responses with 4xx or 5xx HTTP status codes, since these are considered "successful" responses but with a bad status code. In these cases you need to check the response's status property or ok() method via the onResponse callback.

The issue with using react-query alongside openapi-ts + openapi-fetch that I see is that it seems impossible expect if I miss something to grab the response code.

The usage pattern would be:

 const { mutateAsync, isPending: isInviting } = useMutation("post", "/api/async-operation");


const handler = async () => {
  try {
     const res = await mutateAsync(...);
  } catch(error){
    // Here error code should be able to be read if it was Fetch error
   console.log(error) // Error just ends up being the body of the response and nothing else
  }
}

I believe from other issues #2257 #2231 and maybe more.

Reproduction

Expected result

Have the fetch's error response propagated if there is an error thrown.

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions