tRPCttRPC
Powered by
CaptainC
tRPC•4y 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' }),
        });
        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)
  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
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Handling errors on the front-end
OutisOOutis / ❓-help
3y ago
default TRPCError, try/catch & dealing with DatabaseErrors
kgniKkgni / ❓-help
2y ago
Dynamic input not leading to changes on the front end
MiNiMALMMiNiMAL / ❓-help
3y ago
Customizing the TRPCError type
Emmie PäivärintaEEmmie Päivärinta / ❓-help
6mo ago