Skip to content

Autogenerated Fetcher Throws Error on 204 No ContentΒ #257

@benjamin-musil

Description

@benjamin-musil

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions