Skip to content

Possibility to access the response status code for "not ok" responses. #2238

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

Open
1 task
stanleyk opened this issue Mar 31, 2025 · 1 comment
Open
1 task
Labels
enhancement New feature or request openapi-react-query Relevant to openapi-react-query

Comments

@stanleyk
Copy link
Contributor

Description

The current implementation handles all of the !response.ok cases by putting the response body into the error field. This makes it impossible to distinguish whether it was a 404 error (a legitimate case when the resource is not found) or some other error (i.e. a 500 error). In the first case I want to show the user a "Item not found" message, while in the other cases I probably want to show a "Error fetching the data" message and maybe log the error so that it can be fixed. Now I can only distinguish these cases by checking the content of the response, but this might be unsolvable in cases where the BE does not provide any general response for 404 responses that can be relied on.
The only workaround I found is to implement an openapi-fetch middleware and wrap the status code into the response. But this makes the expected response TS type differ from the actual enhanced type, which is quite painful.

Proposal

I am not sure what the best solution might be. The error could be an "enhanced" response body: error: { responseBody: ResponseType; responseStatus: number; }. But this introduces a nasty BC break which is probably not justifiable. Maybe if there was a configuration option to opt in for this behavior? I don't like this kind of configuration options either...

Extra

@zeecou
Copy link

zeecou commented Apr 24, 2025

#2257 touches upon this matter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-react-query Relevant to openapi-react-query
Projects
None yet
Development

No branches or pull requests

2 participants