From 93bfc241ee69def332ab52af399a2ea7a01b28c3 Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Wed, 18 May 2022 09:23:27 -0700 Subject: [PATCH] update readme --- README.md | 1 + recipes/error-handling.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 recipes/error-handling.md diff --git a/README.md b/README.md index 45d1c61..a3f87d9 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ console.log(farewell); // => 👈 goodbye - [Validation](/recipes/validation.md) - [Authorization](/recipes/authorization.md) +- [Error Handling](/recipes/error-handling.md) Learn more about tRPC.io [here](https://trpc.io/docs). diff --git a/recipes/error-handling.md b/recipes/error-handling.md new file mode 100644 index 0000000..1821349 --- /dev/null +++ b/recipes/error-handling.md @@ -0,0 +1,15 @@ +## Handling errors + +All errors that occur in a procedure go through the `onError` method before being sent to the client. Here you can handle or change errors. + +```ts +// ~/server/trpc/index.ts +import * as trpc from '@trpc/server' + +export function onError({ error, type, path, input, ctx, req }) { + console.error('Error:', error) + if (error.code === 'INTERNAL_SERVER_ERROR') { + // send to bug reporting + } +} +```