openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

Autogenerated Fetcher Throws Error on 204 No Content

Open benjamin-musil opened this issue 1 year ago • 0 comments

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.

benjamin-musil avatar Jun 19 '24 21:06 benjamin-musil