CaptainC
tRPC4y ago
14 replies
Captain

Catch TRPCError, ZoddError on the front-end

i am throwing a TRPCError in a mutation. i dont understand how to catch this error in the OnError method. Please help me with this.

i have the following:

ServerSide
        throw new TRPCError({
            message: 'Password changed too recently',
            code: 'BAD_REQUEST',
            cause: Error("You can only modify your password once a day", { cause: 'VALIDATION_ERROR' }),
        });


ClientSide
  const { code, message, name, cause, stack } = error as TRPCError

            console.log(code, message, name, cause, stack)


everyting is undefined except for message. but i'd like to include ZodError to the cause. doesn't work either.

browser console.
image.png
Was this page helpful?