mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-19 14:31:45 +01:00
add error formatting recipe
This commit is contained in:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user