T
tRPC

Catch TRPCError, ZoddError on the front-end

Catch TRPCError, ZoddError on the front-end

CCaptain12/10/2022
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.
CCaptain12/10/2022
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
}
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
AKAlex / KATT 🐱12/10/2022
Add the actual zod error as the cause in the trpc error instead Then use error.cause
CCaptain12/10/2022
errors.cause is undefined when on client
AKAlex / KATT 🐱12/10/2022
On the client? If you want to propagate to the client you need error formatting https://trpc.io/docs/error-formatting And it'll be a TRPCClientError
CCaptain12/11/2022
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
AKAlex / KATT 🐱12/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
Mmsalsbery12/11/2022
Good to know! (The first part I mean, I knew the second part)

Looking for more? Join the community!

T
tRPC

Catch TRPCError, ZoddError on the front-end

Join Server
Recommended Posts
implicitly has type 'any' because it does not have a type annotation and is referenced directlyRunning into this error. I feel like it's some sort of infinite recursion issue, but not sure where Why do some examples create PrismaClient in context, and others don’tIs there a specific reason to do this or not to do this? I can imagine with the new Prisma extensionAppRouter type any?I am trying to use trpc in a Turbo repo and when I export the AppRouter on the server side it is thez.map() as an inputHi, I have ```ts z.map(z.string(), z.string()) ``` as an input, but when I try to pass the map as correct way to call TRPC inside a functioni want a user to be able to sign after they have a clicked a button but i get a hooks error. can anyuse tRPC for RPC calls instead of gRPCHi, I know that tRPC and gRPC are different things - despite the similar name. Nevertheless I woutRPC caching vs Vercel dynamic edge cachingWhat is the difference, or improvements, on Vercel's dynamic edge caching? tRPC server caching worksIgnore Errors from batch callsI have some of my routers throw helpful errors for the client to use in the error message object, buAny way to view headers in middleware?Middleware `input` doesn't seem to have it :/trying to cache api routesHello. I am using TRPC to make a site which integrates with a third party API. I need to add cachinPrisma+TRPC monorepoHey, so we have a monorepo with 3 backend services and 3 frontend services. It looks like the followcalling api endpoints from within a trpc api endpoint?Hey all. I have a series of api endpoints which may have to be reused across other api endpoints. ITRPC waiting until the query has completedHey. I've just found out about TRPC and I love it. However, I was wondering if there is a way to maktrpc with headless cmsHello, Is there any example with trpc and headless CMS or is there anypoint to use trpc for project Is it possible to call a query from another query defined in the same router?Say I have some code like the following: ``` t.router({ compute_all: t.procedure .query(Testing with React Testing LibraryHi! I am trying to test my ```DestinationForm``` component using react testing library. My test is sProxy TRPC server to another clientI've two TRPC servers, one essentially acts like a proxy, it validates auth and based on a specific Unexpected tokenhi, kindly help me on this oneDelay IsLoading....i'm trying to delay a loading spinner from appearing if the api takes less than 200ms to get the datClearing CacheHow do I clear the queryCache for a particular query using the trpc context? If that's not possible,