TanStack / TanStack/router

Response.json() thrown in server functions not caught by error boundaries or React Query

Open
#6,900 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.