Response.json() thrown in server functions not caught by error boundaries or React Query
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Router
Describe the bug
Bug: Response.json() thrown in server functions not caught by error boundaries or React Query
Description
When throwing Response.json(...) inside a TanStack Start server function (createServerFn), the error is not caught by error boundaries and React Query fails to recognize it as an error. This impacts useQuery, useMutation, and potentially other APIs.
In older versions of TanStack Start, throw json({...}) was caught similarly to a regular error. The current behavior with Response.json() is a regression.
Your Example Website or App
https://github.com/uap-dev/tanstack-bug-response-json
Steps to Reproduce the Bug or Issue
See README.MD in repo, includes repro steps
Expected behavior
Throwing Response.json(...) with a non-2xx status from a server function should be caught by error boundaries and recognized as an error by React Query — the same way throw new Error(...) works.
Screenshots or Videos
N/A
Platform
- Router / Start Version: 1.166.7 / 1.166.8
- OS: macOS (Darwin 24.3.0)
- Browser: Chrome
- Browser Version: 145.0.7632.160
- Bundler: Vite
- Bundler Version: 7.3.1
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with README.MD in the linked reproduction repository and reproduce a TanStack Start createServerFn that throws Response.json(...) with a non-2xx status. Trace how the result reaches error boundaries, useQuery, and useMutation; done means it is recognized as an error like throw new Error(...).
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- backend-api-design, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100