diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-13 22:37:41 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2024-03-14 16:40:45 +0000 |
| commit | a03f1dc2ac25579df30e8cb59d2703110c3e564d (patch) | |
| tree | 59315e73cd83dc391660071c70752cf23989b3da /packages/trpc/index.ts | |
| parent | 04572a8e5081b1e4871e273cde9dbaaa44c52fe0 (diff) | |
| download | karakeep-a03f1dc2ac25579df30e8cb59d2703110c3e564d.tar.zst | |
lint: Lint and format the entire repo with the new configs
Diffstat (limited to 'packages/trpc/index.ts')
| -rw-r--r-- | packages/trpc/index.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/packages/trpc/index.ts b/packages/trpc/index.ts index bcfa7211..51c713c0 100644 --- a/packages/trpc/index.ts +++ b/packages/trpc/index.ts @@ -2,6 +2,7 @@ import { db } from "@hoarder/db"; import serverConfig from "@hoarder/shared/config"; import { TRPCError, initTRPC } from "@trpc/server"; import superjson from "superjson"; +import { ZodError } from "zod"; type User = { id: string; @@ -21,6 +22,19 @@ export type Context = { // is common in i18n libraries. const t = initTRPC.context<Context>().create({ transformer: superjson, + errorFormatter(opts) { + const { shape, error } = opts; + return { + ...shape, + data: { + ...shape.data, + zodError: + error.code === 'BAD_REQUEST' && error.cause instanceof ZodError + ? error.cause.flatten() + : null, + }, + }; + }, }); export const createCallerFactory = t.createCallerFactory; // Base router and procedure helpers |
