mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-31 04:07:55 +01:00
add error formatting recipe
This commit is contained in:
@@ -15,7 +15,7 @@ export const router = trpc.router<Context>()
|
|||||||
data: {
|
data: {
|
||||||
...shape.data,
|
...shape.data,
|
||||||
zodError:
|
zodError:
|
||||||
error.code === 'BAD_USER_INPUT'
|
error.code === 'BAD_REQUEST'
|
||||||
&& error.cause instanceof ZodError
|
&& error.cause instanceof ZodError
|
||||||
? error.cause.flatten()
|
? error.cause.flatten()
|
||||||
: null,
|
: null,
|
||||||
@@ -27,5 +27,15 @@ export const router = trpc.router<Context>()
|
|||||||
### Usage in Vue
|
### Usage in Vue
|
||||||
|
|
||||||
```html
|
```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