import { ProcedureType } from '../'; import { TRPC_ERROR_CODE_KEY, TRPC_ERROR_CODE_NUMBER, TRPCErrorShape, } from '../rpc'; import { TRPCError } from './TRPCError'; /** * @internal */ export type ErrorFormatter> = ({ error, }: { error: TRPCError; type: ProcedureType | 'unknown'; path: string | undefined; input: unknown; ctx: TContext | undefined; shape: DefaultErrorShape; }) => TShape; export type ErrorFormatterShape = TType extends ErrorFormatter< any, infer TShape > ? TShape : DefaultErrorShape; /** * @internal */ export type DefaultErrorData = { code: TRPC_ERROR_CODE_KEY; httpStatus: number; path?: string; stack?: string; }; /** * @internal */ export interface DefaultErrorShape extends TRPCErrorShape { message: string; code: TRPC_ERROR_CODE_NUMBER; } export const defaultFormatter: ErrorFormatter = ({ shape, }: { shape: DefaultErrorShape; }) => { return shape; };