Skip to content

fix(openapi-react-query): propagate undefined errors from empty-body non-OK responses#2829

Open
EduardF1 wants to merge 2 commits into
openapi-ts:mainfrom
EduardF1:fix/propagate-undefined-errors-openapi-react-query-v2
Open

fix(openapi-react-query): propagate undefined errors from empty-body non-OK responses#2829
EduardF1 wants to merge 2 commits into
openapi-ts:mainfrom
EduardF1:fix/propagate-undefined-errors-openapi-react-query-v2

Conversation

@EduardF1

Copy link
Copy Markdown

Closes #2070.

What changed and why

  • Update queryFn, useInfiniteQuery's queryFn, and mutationFn to throw when error !== undefined || !response.ok
  • Destructure response in the two places it was missing so the non-OK HTTP status is available
  • Add regression tests covering empty-body non-OK responses for query, mutation, and infinite query paths

Scenario fixed

When openapi-fetch returns { data: undefined, error: undefined, response } for a non-OK response with an empty body (e.g. a 4xx/5xx response with Content-Length: 0), the previous if (error) check treated the result as successful and silently swallowed the failure. This PR propagates those errors correctly by also checking response.ok.

Test plan

  • pnpm test passes in packages/openapi-react-query (40 tests, all green)
  • Three new tests added: one each for queryOptions, useMutation, and useInfiniteQuery, asserting that empty-body 500 responses are correctly rejected/thrown

Notes

This is a re-submission of #2822, which was closed because the branch was accidentally created as an orphan (not based on main) causing 1.8M spurious additions. This PR is cleanly branched from main with only the intended 91-line diff (10 source lines + 81 test lines).

…non-OK responses

When openapi-fetch returns { data: undefined, error: undefined, response }
for a non-OK response with an empty body (e.g. 4xx/5xx with Content-Length: 0),
the previous `if (error)` check treated the result as successful and swallowed
the failure. Fix by checking `error !== undefined || !response.ok` in queryFn,
useInfiniteQuery's queryFn, and mutationFn.

Closes openapi-ts#2070.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@EduardF1 EduardF1 requested a review from a team as a code owner June 16, 2026 09:12
@EduardF1 EduardF1 requested a review from drwpow June 16, 2026 09:12
@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 193cb06

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-react-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Jun 16, 2026

Copy link
Copy Markdown

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 193cb06

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant