Hi all, My TRPC route can sometimes fail. Say the error is
CartValidationError
CartValidationError
In the frontend, I want to be able to do:
try { await trpcProxyClient.user.cart.addCoupon.mutate({ ...payload, cartOwner })} except (error) { if (error instanceof CartValidationError) { // do thing } else { // do other thing }}
try { await trpcProxyClient.user.cart.addCoupon.mutate({ ...payload, cartOwner })} except (error) { if (error instanceof CartValidationError) { // do thing } else { // do other thing }}
The problem is that the error is of type TRPCClientError. In the backend, I can see that the
error.cause
error.cause
is what has the real error (
CartValidationError
CartValidationError
)
Is there a way for me to make the backend return the error in it's original type so I can use instanceOf? If not, can I use error.cause in the frontend? (doesn't seem possible yet)