icflorescu / trpc-sveltekit-example

A sample SvelteKit application built to illustrate the usage of ✨ trpc-sveltekit.
https://icflorescu.github.io/trpc-sveltekit
ISC License
136 stars 18 forks source link

Request for error handling example #15

Closed caschbre closed 1 year ago

caschbre commented 1 year ago

I was reading through the tRPC Error Handling docs, but wasn't quite sure how to implement that using trpc-sveltekit.

I figured this example project would be a great place for that. :-)

icflorescu commented 1 year ago

What do you mean? Like here?

caschbre commented 1 year ago

Ah, sorry I wasn't very clear. I was looking at the error handling example provided in the trpc docs.

export default trpcNext.createNextApiHandler({
  // ...
  onError({ error, type, path, input, ctx, req }) {
    console.error('Error:', error);
    if (error.code === 'INTERNAL_SERVER_ERROR') {
      // send to bug reporting
    }
  },
});
icflorescu commented 1 year ago

Ah, I see, you mean handling on the server. I did not expose onError as a parameter of createTRPCHandle, but I guess I should. Will release a new version shortly.

icflorescu commented 1 year ago

Landed in v3.1.0. Look at the bottom of the page here: https://icflorescu.github.io/trpc-sveltekit/handling-errors Basically you can now provide an onError function to createTRPCHandle.

caschbre commented 1 year ago

Awesome! Exactly what I was looking for. Thanks!