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

Autogenerated Fetcher Throws Error on 204 No Content #257

Open
benjamin-musil opened this issue Jun 19, 2024 · 0 comments
Open

Autogenerated Fetcher Throws Error on 204 No Content #257

benjamin-musil opened this issue Jun 19, 2024 · 0 comments

Comments

@benjamin-musil
Copy link

Problem

Was running into an issue when our backend openapi spec'd response for an endpoint was a 204 No Content success status. The client side code was throwing an error so we couldn't trigger the onSuccess function through the react query component. The error was the following thrown in the autogenerated fetcher script:

message: "Network error (Unexpected end of JSON input)"name: "unknown"stack: SyntaxError: Unexpected end of JSON input

Workaround

Check the response status in the fetcher AFTER the fetch, e.g.

if (response.status === 204) {
    return {} as TData;
}

Could also return null or something else you want.

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

No branches or pull requests

1 participant