add error formatting recipe

This commit is contained in:
Robert Soriano
2022-05-19 00:47:15 -07:00
parent 4ac104943d
commit 1ef0caa18e

View File

@@ -15,7 +15,7 @@ export const router = trpc.router<Context>()
data: {
...shape.data,
zodError:
error.code === 'BAD_USER_INPUT'
error.code === 'BAD_REQUEST'
&& error.cause instanceof ZodError
? error.cause.flatten()
: null,
@@ -27,5 +27,15 @@ export const router = trpc.router<Context>()
### Usage in Vue
```html
<script setup lang="ts">
const { error } = await useAsyncQuery(['getUser', { id: 69 }])
</script>
<template>
<pre v-if="error?.data?.zodError">
{{ JSON.stringify(error.data.zodError, null, 2) }}
</pre>
</template>
```
Learn more about error formatting [here](https://trpc.io/docs/error-formatting).