TkDodo ๐Ÿ”ฎT
tRPCโ€ข3y agoโ€ข
5 replies
TkDodo ๐Ÿ”ฎ

TRPCError that has TRPCError as cause

Having some troubles with error handling, specifically, my errors are double-wrapped in a TRPCError.

What I'm doing is basically having a mutation that does:

something: t.procedure
  .input(mySchema)
  .mutation() => Promise.reject(new Error('oh no'))),


and then, the onError handler has:

onError({ error }) {
  console.log('onError', error.name, error.cause.name)
},


which logs: onError TRPCError TRPCError. If I then go further with error.cause.cause.name, I can see my error.

I already tried to reproduce this in isolation, but in a sandbox, I get:

onError TRPCError Error, which is what I would expect.

Just wanted to know if anyone has seen something similar; Not sure how this can happen ... thanks
Was this page helpful?