throwing custom errors from mutations

any idea why trpc is ignoring the catch expression? it just throws its own error about unique constraint violation
No description
Mikey
Mikey261d ago
@asheeshh try checking the type of your error. You may need to do an if check against TRPC error first and then throw a new error based on what you're experiencing.
asheeshh
asheeshh261d ago
youre asking me to check the error type on the client side?
Mikey
Mikey261d ago
In the catch, console log out the instanceof for e BEFORE you get into the if statement. @asheeshh
asheeshh
asheeshh261d ago
oh actually the thing is my catch expression is completely ignored by trpc nothing inside catch runs already tried console logging stuff inside it
Mikey
Mikey261d ago
Can you share your current code and the console.log for it?
asheeshh
asheeshh261d ago
console log? of what?
Mikey
Mikey261d ago
This right here...which you said you already did.
asheeshh
asheeshh261d ago
this is the error thrown by trpc
No description
asheeshh
asheeshh261d ago
i just added a console log inside catch to print the error
Mikey
Mikey261d ago
Put this before your if statement in the catch block. console.log(e instanceof TRPCClientError) If this is true, then that means you will never run the code in your if statement.
asheeshh
asheeshh261d ago
nothing inside or outside of the if statements is running the whole catch expression doesnt run when an error is thrown
Mikey
Mikey261d ago
Without seeing the rest of your code, it's difficult to help you. But try looking at this: https://trpc.io/docs/client/vanilla/infer-types#infer-trpcclienterror-types
Inferring Types | tRPC
It is often useful to access the types of your API within your clients. For this purpose, you are able to infer the types contained in your AppRouter.
Mikey
Mikey261d ago
This explains how to get the type from a TRPCClientError
Dani;
Dani;260d ago
Pretty sure you need to await the promise inside the try-catch block
More Posts
trpc in a pnpm monorepoHi all 👋 I was wondering if there is a recommended setup for monorepos, in our case with pnpm workTS Error with React when creating client "useContext" collides ....when creating the client i get following error: The property 'useContext' in your router collides wType 'NextRequest' is missing properties from type 'NextApiRequest'Enviorment: Node 18, pnpm Hi, I'm facing an error, where in my app i get this error at `createTRPCCType '{}' is not assignable in server queryType '{ input: { slug: string; }; "": any; }' is not assignable to type 'string | StringFilter<"CateThe inferred type of this node exceeds the maximum length the compiler will serialize.Using HTTP:POST for `query`?Hey guys, thanks for the awesome library! My application involves making a `query` with a large amre validation on static site next js 13Hi, does any one know how to make revaluation when I’m fetching data on the server client from DB wiTransformers not transforming data (trpc-sveltekit)I'm having some trouble getting superjson to do its magic with tRPC & SvelteKit. I have a `client.tsIssue Inferring Type on Frontend with ElectroDB Query Return StatementHi all, I am using ElectroDB to work with DynamoDB, and I have a Lambda function that uses tRPC thaWrong JSON response when deployedWhen testing in localhost in dev mode there is no issue and the response is correct as expected. BuExternal callsHi! I am using T3 stack, tRPC together with clerk, and i need to create users within the app, being Need help identifying the generic client side type of proceduresHi! I think my question is better explained by what I'm trying to achive than anything else: I likIs there a way to use versioning for procedures?I want to make multiple versions (v1 / v2) for a procedure, can i do it in procedure level?createSSGHelpersI'm trying to fetch data in getStaticProps and getting the issue "Promise<{ paths: { params: { id: nTRPC undefined when exportingHi i am working on merging routers from different files but when exporting the router property it coTRPC retries with new app dir```ts let { data: name, isLoading, isFetching, isError, error } = trpc.home.home.useQuery(); ```opts.input is of type undifined```ts register: publicProcedure.input( RegisterSchema ).mutation(async (opts) => { Server-side error tracing with DatadogHey, has anyone had any luck setting up tracing with tRPC? Specifically with `dd-trace-js`. We’re uConfiguration helpHello! I want to apply the following configuration on the client: https://tanstack.com/query/v4/docI'm curious to know if anyone has any suggestions on how I can track the replies to the emailsI'm curious to know if anyone has any suggestions on how I can track the replies to the emails I sen