From a03f1dc2ac25579df30e8cb59d2703110c3e564d Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 13 Mar 2024 22:37:41 +0000 Subject: lint: Lint and format the entire repo with the new configs --- packages/shared/index.ts | 2 +- packages/trpc/index.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/shared/index.ts b/packages/shared/index.ts index 8b93520f..e449443d 100644 --- a/packages/shared/index.ts +++ b/packages/shared/index.ts @@ -1 +1 @@ -export * as Queues from "./queues.ts"; +export * as Queues from "./queues"; 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().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 -- cgit v1.2.3-70-g09d2