add onError handler

This commit is contained in:
Robert Soriano
2022-05-18 09:09:11 -07:00
parent 83624e0ca8
commit 3eda32d33a
3 changed files with 13 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
const client = useClient()
const data = await client.query('getUser', {
name: 'roberts',
const { data, error } = await useAsyncData('random', () => client.query('hello'), {
server: false,
})
</script>

View File

@@ -1,35 +0,0 @@
import * as trpc from '@trpc/server'
import { z } from 'zod'
import type { CompatibilityEvent } from 'h3'
export const router = trpc
.router()
.query('getUser', {
input: z.object({ name: z.string().min(5) }),
async resolve(req) {
return { id: 1, name: req.input.name }
},
})
.query('hello', {
resolve: () => 'world',
})
// optional
export const createContext = (event: CompatibilityEvent) => {
return {
user: {
id: 69,
name: 'robert',
},
}
}
// optional
export const responseMeta = () => {
// ...
return {
// { headers: ... }
}
}
export type Router = typeof router