icflorescu / trpc-sveltekit

End-to-end typesafe APIs with tRPC.io for your SvelteKit applications.

Home Page:https://icflorescu.github.io/trpc-sveltekit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling Errors

clonecorp opened this issue · comments

Hey there,

Iam trying to handle the TRPCErrors as well as other types of errors like the ZodErrors or the Prisma ones so that my frontend knows how to react based on each and every one of them. But I see that trpc-sveltekit sends a plain object to the client instead of the object described in the trpc docs here: https://trpc.io/docs/error-handling#throwing-errors

I tried also using the error formatter here: https://trpc.io/docs/error-formatting#adding-custom-formatting but since the client doesn't get a full object, I can only use the message in my try catch blocks. Is there a way to get the full TRPCErrors on the frontend.

I see the Bookstall example doesn't really handle them neither. And since there's no type inferred to the errors, it makes it impossible to handle correctly.

Any help on that @icflorescu ?

The rest works so far flawlessly I must say.

commented

tried to throw TRPCClientError instead of TRPCError?

TRPCError is handled from createTRPCHandle({onError: ({}) => but I am unable to get access to handle TRPCClientError. Read need access to Link to handle TRPCClientError

@JonathonRP if it helps, you can now create a client by providing your own links like so:

const client = createTRPCClient<Router>({ links: [
  // your custom links...
] });

@clonecorp Sorry for the late reply. Can you please be more specific and describe how exactly would you like to handle errors?

@clonecorp Sorry for the late reply. Can you please be more specific and describe how exactly would you like to handle errors?

Hey there.

I've been playing around with the Express adapter from tRPC and apparently the object received on the frontend is identical to the one I receive with the adapter you built.

I expected to receive a full object error as described in the tRPC docs but apparently that's not happening, so I'm going to close this one as I think it seems to be a normal behavior.