update readme

This commit is contained in:
Robert Soriano
2022-05-18 09:23:27 -07:00
parent cec8ea52d6
commit 93bfc241ee
2 changed files with 16 additions and 0 deletions

View File

@@ -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).

15
recipes/error-handling.md Normal file
View File

@@ -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
}
}
```