Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Accessing body of error response #342

Open
sarahannali opened this issue Apr 1, 2021 · 0 comments
Open

Accessing body of error response #342

sarahannali opened this issue Apr 1, 2021 · 0 comments

Comments

@sarahannali
Copy link

sarahannali commented Apr 1, 2021

I'm currently trying to make my post request handle a specific error message. The response body of the error message is fine through postman, but the output of the error to the console is:

data: Response
  body: ReadableStream
  bodyUsed: true
  headers: Headers {}
  ok: false
  redirected: false
  status: 400
  statusText: ""
  type: "basic"
  url: "https://localhost:3003/api/type"
message: "Failed to fetch: 400 "
status: 400

which is the correct response, but the body is a readable stream. I can access the body by reading this stream, but it's clunky. I'd like to be able to just output my error.data.body.

Perhaps I'm just running my request wrong. Here's how it's formatted:

const addType = useAddType({}); // generated post function for API named AddType that takes in a name

  addType
      .mutate({
          name: "testName"
      })
      .then(res => {
          console.log(res);
      })
      .catch(err => {
          console.log(err); // contains a body with a more detailed error message
      })

This request works fine, I just can't access the body of the error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant