Exception in catch block: TypeError: Response.text: Body has already been consumed.
#1544
Labels
bug
Something isn't working
good first issue
Straightforward problem, solvable for first-time contributors without deep knowledge of the project
openapi-fetch
Relevant to the openapi-fetch library
PRs welcome
PRs are welcome to solve this issue!
Description
If the error response is not JSON, this will raise a type error rather than returning the error body text.
Reproduction
Use the fetch API to hit an endpoint that returns a 4xx response with invalid JSON (i.e. plaintext). Based on debugging, the following is the issue:
await response.json();
seems to first consume the body, then try parsing JSON. If reading the body succeeds but parsing the JSON fails, then thecatch
block will hit andresponse.text()
will fail (since the body has already been consumed).Expected result
error
should probably still contain the error text, even if the response is non-JSON. I believe that the below would fix this:Checklist
The text was updated successfully, but these errors were encountered: