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>
@EduardF1

Copy link
Copy Markdown
Author

Status update + root-cause of the failing lint check

The bug fix is verified. I built the workspace deps (openapi-typescript-helpers, openapi-fetch) and ran the package suite locally:

✓ test/index.test.tsx (40 tests) 1393ms
Test Files  1 passed (1)
     Tests  40 passed (40)

All 40 tests pass, including the three new regression tests (empty-body non-OK responses for queryOptions, useMutation, and useInfiniteQuery). The Uncaught { code: 500 } lines in the output are just jsdom echoing the intentionally-mocked 500 responses — not test failures.

The failing lint check is not caused by this PR. The job fails at openapi-react-query#lintbiome check .. The flagged items are all in pre-existing code that this PR does not touch:

  • test/index.test.tsx:870 / :873noUnusedFunctionParameters (context in the onError/onSettled mutation test)
  • test/index.test.tsx:1129 / :1256 / :1292noUnusedVariables (firstRequestHandler / secondRequestHandler in the pagination tests)
  • a Biome format diff in pre-existing lines

Root cause is a Biome version drift: @biomejs/biome is pinned to 2.4.14 while biome.json still declares "$schema": ".../2.3.14/schema.json". Biome 2.4.14 newly enforces these correctness/* rules. I reproduced the identical violations against main itself (origin/main:packages/openapi-react-query/test/index.test.tsx, lines 850/853/1085/1212/1248), so every open PR is currently blocked by this — main's last green CI predates the bump.

For completeness, this PR's own added test blocks are Biome-clean (no new lint/format findings).

Suggested resolution (maintainers): land a small maintenance change on mainbiome migrate to sync the schema, then biome check --write --unsafe for the pre-existing noUnusedVariables/noUnusedFunctionParameters + format — or pin Biome back to 2.3.x. Once main is green, this PR's lint will pass (it's already MERGEABLE).

I'm happy to (a) fold the safe Biome auto-fixes into this PR to unblock CI immediately, or (b) rebase onto current main, whichever you prefer — just let me know.

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