tRPC Error handling

im trying to understand how tRPC handle 400 errors request what i got so far is im doing this in my procedure
if (exam) throw new TRPCError({ code: "BAD_REQUEST" });
if (exam) throw new TRPCError({ code: "BAD_REQUEST" });
and in client im getting an error like so but i want to handle the error in client as i want without getting the nextjs error ui i just want a response with message and 400 status the equivalent of if (exam) res.status(400).json({message:"you have an error"}) in express
3 Replies
jingleberry
jingleberry2y ago
In your useQuery you can extract the error variable and inspect it to see what it contains. Then you can render what you need. Although it depends, if you are using suspense you will need to catch the error with an error boundary instead
H
H2y ago
yea that what i did i handled the error in a try catch
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server