openapi-codegen
openapi-codegen copied to clipboard
Autogenerated Fetcher Throws Error on 204 No Content
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.