icflorescu/trpc-sveltekit

Update error handling example

Ennoriel opened this issue · 1 comments

Describe the bug
On the documentation page handling errors, there is this statement:

errors = JSON.parse(err.message);

I wasn't able to make this work. I did instead:

errors = err.message;

I was confused because Object.keys(err) doesn't return the property message (maybe because it's a class getter?). I don't know if this is a change induced by SK2 or if I am missing something here.

To Reproduce
Go to the documentation page handling errors.

Expected behavior
If errors = err.message; is the right solution, I'd suggest to update the doc.

Desktop (please complete the following information):

  • trpc-sveltekit: 3.5.22
  • trpc: 10.45.0
  • @sveltejs/kit: 2.3.2
  • svelte: 4.2.8

The doc page is more of a guideline, and it works fine in the context of the bookstall test application is referring to.
In that context, the zod errors are handled properly.

Error handling, however, highly depends on the specific of each project, so feel free to proceed according to your own requirements.