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

openapi-react-query does not propagate undefined errors from openapi-fetch #2070

Open
OliverJAsh opened this issue Dec 26, 2024 · 1 comment
Assignees
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-react-query Relevant to openapi-react-query

Comments

@OliverJAsh
Copy link

OliverJAsh commented Dec 26, 2024

openapi-fetch may return an error of value undefined, when content length is 0 and response is not okay:

// handle empty content
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
return response.ok ? { data: undefined, response } : { error: undefined, response };
}

However, openapi-react-query does not propagate this error, because the error is only propagated when error is truthy, as per this code:

if (error) {
throw error;
}

To fix this, I believe this if (error) check should be if (!response.ok) and/or if ('error' in result).

We might also want to consider whether it makes sense for openapi-fetch to return undefined as an error, in the scenario mentioned above.

@OliverJAsh OliverJAsh added bug Something isn't working openapi-react-query Relevant to openapi-react-query labels Dec 26, 2024
@kerwanp
Copy link
Contributor

kerwanp commented Dec 29, 2024

That makes completely sense, happy to review a PR for that!

@kerwanp kerwanp added the good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project label Dec 29, 2024
@kerwanp kerwanp self-assigned this Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-react-query Relevant to openapi-react-query
Projects
None yet
Development

No branches or pull requests

2 participants