BumblebeeB
tRPC13mo ago
2 replies
Bumblebee

Client receives 200 status when throwing TRPCError

Using pnpm, Next 14 app router and tRPC v11 mainly based on create-t3-turbo.

If I have a query on the client and then throw, for example, a TRPCError with code UNAUTHORIZED, the client is getting back a 200 rather than a 401.
const handler = async (req: Request) => {
  ...
  const response = await fetchRequestHandler({
    endpoint: "/api/trpc",
    router: appRouter,
    req,
    createContext: () =>
      createTRPCContext({
        ...
      }),
    onError({ error, path }) {
      console.error(`>>> tRPC Error on '${path}'`, error);
    },
  });

  setCorsHeaders(response);
  return response;
};

The onError callback is properly getting and logging the 401 but the response sent to the client is a 200. Is there any way to propagate the error to the client?

The same behaviour can be seen on a fresh create-t3-app if a repro is wanted
Was this page helpful?