update readme

This commit is contained in:
Robert Soriano
2022-05-19 00:38:27 -07:00
parent a3d2f61861
commit 4ac104943d
7 changed files with 130 additions and 60 deletions

View File

@@ -0,0 +1,31 @@
## Error Formatting
The error formatting in your router will be inferred all the way to your client (& Vue components).
### Adding custom formatting
```ts
// ~/server/trpc/index.ts
import * as trpc from '@trpc/server'
export const router = trpc.router<Context>()
.formatError(({ shape, error }) => {
return {
...shape,
data: {
...shape.data,
zodError:
error.code === 'BAD_USER_INPUT'
&& error.cause instanceof ZodError
? error.cause.flatten()
: null,
}
}
})
```
### Usage in Vue
```html
```