Skip to content

Server routers can't return 401 responses #7200

@masylum

Description

@masylum

Which project does this relate to?

Router

Describe the bug

Whenever I try to return a 401 response, tanstack router chokes.

Your Example Website or App

pasted the code below

Steps to Reproduce the Bug or Issue

export const Route = createFileRoute("/api/workers/")({
server: {
handlers: {
POST: async ({ request }) => {
return Response.json({ error: "unauthorized" }, { status: 401 })
},
},
},
})
[vite] Internal server error: fetch failed
at Object.processResponse (/Users/pao/repos/ramensoft/node_modules/.pnpm/undici@7.24.4/node_modules/undici/lib/web/fetch/index.js:237:16)
at /Users/pao/repos/ramensoft/node_modules/.pnpm/undici@7.24.4/node_modules/undici/lib/web/fetch/index.js:1081:19
at node:internal/process/task_queues:151:7
at AsyncResource.runInAsyncScope (node:async_hooks:214:14)
at AsyncResource.runMicrotask (node:internal/process/task_queues:148:8)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at /Users/pao/repos/ramensoft/node_modules/.pnpm/undici@7.24.4/node_modules/undici/index.js:157:7
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Change that status to anything else and it works

Expected behavior

It should work

Screenshots or Videos

No response

Platform

@cloudflare/vite-plugin 1.32.2
@tanstack/react-router 1.168.10
@tanstack/react-start 1.167.16
vite 8.0.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions