TRPC Server error handling?

So I've been refactoring my old project with T3 +app router that @julius recently added to T3 stack and I was just fiddling around trpc and its context I stumbled upon a problem. I have a trpc middleware that checks for authed user enforceUserIsAuthed
const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
if (!ctx.sessionIdToken) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}

return next({
ctx: {
...
},
});
});
const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
if (!ctx.sessionIdToken) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}

return next({
ctx: {
...
},
});
});
And there is a problem. When I use the client trpc calls (react) I have a onError props for queryclient that I can check for that error and react (especially for 401 and redirect). But when it throws in the RSC this triggers error boundaries and throws uncaught TRPCClienterror. How am I supposed to handle server errors in this case? createTRPCProxyClient doesnt seem to have any onerror handler.
3 Replies
julius
julius12mo ago
dont @ maintainers pls
Mugetsu
Mugetsu12mo ago
my apology. Out of habit 🤦‍♂️
Akmal Dira
Akmal Dira3mo ago
Have you solve that? @Mugetsu ?
Want results from more Discord servers?
Add your server