diff --git a/playground/server/trpc/trpc.ts b/playground/server/trpc/trpc.ts index 50e3559..c090769 100644 --- a/playground/server/trpc/trpc.ts +++ b/playground/server/trpc/trpc.ts @@ -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().create({ transformer: superjson, + errorFormatter({ shape, error }) { + return { + ...shape, + data: { + ...shape.data, + zodError: + error.code === 'BAD_REQUEST' + && error.cause instanceof ZodError + ? error.cause!.flatten() + : null, + }, + } + }, }) /**