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:

        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' }),

  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.
const error: TRPCError = {
            name: "TRPCError",
            code: "BAD_REQUEST",
            message: "\"password\" must be at least 4 characters"

        if (error instanceof TRPCError) {
            const httpCode = getHTTPStatusCodeFromError(error);
            console.log(httpCode); // 400
the console.log inside the if statement doesnt get printed
A/Kalex / KATT12/10/2022
Add the actual zod error as the cause in the trpc error instead
A/Kalex / KATT12/10/2022
Then use error.cause
errors.cause is undefined when on client
A/Kalex / KATT12/10/2022
On the client? If you want to propagate to the client you need error formatting
A/Kalex / KATT12/10/2022
And it'll be a TRPCClientError
to want to catch the zod parse error, you actually have to throw a zodError
should be included in the docs in my opinion
also dont flatten the error when formatting
also dont safparse
A/Kalex / KATT12/11/2022
feel free to improve the docs! 🙂 would love some help!

none of the people working on trpc does it as a full-time job
Good to know! (The first part I mean, I knew the second part)