Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No content (204) responses throw unparseable error #171

Closed
DarkGhostHunter opened this issue Nov 20, 2022 · 1 comment
Closed

No content (204) responses throw unparseable error #171

DarkGhostHunter opened this issue Nov 20, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@DarkGhostHunter
Copy link

An endpoint that returns a HTTP 204 response without body.

The culprit is this line of code:

   // We override the `.json()` method to parse the body more securely with `destr`
    if (responseType === "json") {
      const data = await context.response.text();
      const parseFunction = context.options.parseResponse || destr;
      context.response._data = parseFunction(data);
    } else if (responseType === "stream") {
      context.response._data = context.response.body;
    } else {
      context.response._data = await context.response[responseType]();
    }

Before this, it has to check if the status code is 204 to skip parsing.

It will also throw the same error on any response without a body.

@nozomuikuta nozomuikuta added the bug Something isn't working label Jan 12, 2023
@nozomuikuta
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants