tRPCttRPC
Powered by
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'))),
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)
},
onError({ error }) {
  console.log('onError', error.name, error.cause.name)
},


which logs:
onError TRPCError TRPCError
onError TRPCError TRPCError
. If I then go further with
error.cause.cause.name
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
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
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Throw custom TRPCError with specific cause
NeonNNeon / โ“-help
4y ago
difference between cause and message on TRPCError?
NickNNick / โ“-help
3y ago
Missing keys in TRPCError when returning as JSON
molochMmoloch / โ“-help
3y ago
TRPCError class, public readonly cause?: Error; this line should have override function
fahadFfahad / โ“-help
3y ago