Skip to content

docs(react): handle failed fetch responses in simple example#10732

Open
0Jaemin0 wants to merge 2 commits into
TanStack:mainfrom
0Jaemin0:fix/react-simple-fetch-error
Open

docs(react): handle failed fetch responses in simple example#10732
0Jaemin0 wants to merge 2 commits into
TanStack:mainfrom
0Jaemin0:fix/react-simple-fetch-error

Conversation

@0Jaemin0
Copy link
Copy Markdown

@0Jaemin0 0Jaemin0 commented May 19, 2026

🎯 Changes

Updates the React simple example and the matching React overview snippet to check response.ok before parsing the GitHub API response.

The browser fetch API resolves successfully for HTTP error responses like 404 or 500, so the query function now throws Request failed with status ${response.status} when the response is not ok. This makes failed HTTP responses surface through TanStack Query's error state in the example.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Documentation
    • Updated React docs and example projects to demonstrate improved HTTP fetch error handling. Examples now validate response status and surface descriptive errors for failed requests, promoting more robust request handling in apps.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba7c8eae-f8bf-4550-b732-d70700479b95

📥 Commits

Reviewing files that changed from the base of the PR and between 0203f84 and cee62d0.

📒 Files selected for processing (1)
  • examples/react/simple/src/index.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/react/simple/src/index.tsx

📝 Walkthrough

Walkthrough

Two files are updated to add HTTP response status validation to React Query fetch functions: the docs example switches from a chained then to an async function that checks response.ok and throws on failure; the same check is added to the simple React example.

Changes

HTTP Error Handling Pattern

Layer / File(s) Summary
HTTP response validation across docs and examples
docs/framework/react/overview.md, examples/react/simple/src/index.tsx
The documentation example and simple example implementation both refactor fetch query functions to await the response, validate response.ok, throw errors with HTTP status on failure, and return parsed JSON on success.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A little fetch that pauses to peek,

If status is broken, it will not speak.
It throws a short message, honest and plain,
Otherwise returns the parsed JSON gain.
Hops on the branch — no surprises remain.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: handling failed fetch responses in the React simple example.
Description check ✅ Passed The description covers the changes, motivation, and includes completed checklist items; however, the 'pnpm run test:pr' testing checkbox is unchecked.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/react/simple/src/index.tsx`:
- Line 33: Replace the unnecessary "await" on the response.json() return so the
async function returns the promise directly (change "return await
response.json()" to "return response.json()"); locate the return statement that
calls response.json() in the fetch/handler function and remove the await to
match the docs and avoid the redundant promise wrapping.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ade9f698-97b2-4687-a184-9bbacd2b44ab

📥 Commits

Reviewing files that changed from the base of the PR and between a4cebdb and 0203f84.

📒 Files selected for processing (2)
  • docs/framework/react/overview.md
  • examples/react/simple/src/index.tsx

Comment thread examples/react/simple/src/index.tsx Outdated
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.

1 participant