add zod error formatting for playground

This commit is contained in:
Robert Soriano
2022-10-30 21:30:07 -07:00
parent 81c7608fb0
commit 41e6117113

View File

@@ -1,9 +1,23 @@
import { initTRPC } from '@trpc/server'
import superjson from 'superjson'
import { ZodError } from 'zod'
import type { Context } from './context'
const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError:
error.code === 'BAD_REQUEST'
&& error.cause instanceof ZodError
? error.cause!.flatten()
: null,
},
}
},
})
/**