What's the type of errorFormatter parameter

I wanna know how could i get the type of the errorFormatter parameter, so i can move the errorFormatter logic to another file. Environment: Node v18.15.0
Nick
Nick377d ago
Right click and go to type definition then start copying things out, if any types you need aren’t already exported then open a GitHub issue and we can do it if it’s sensible
NeoBean
NeoBean287d ago
For others looking for the type, i believe it is ErrorFormatter<Context, DefaultErrorShape>
// `Context` is basically `inferAsyncReturnType<typeof createContext>`
export const errorFormatter: ErrorFormatter<Context, DefaultErrorShape> = opts => {
/** do your things, maybe replace DefaultErrorShape */
return opts.shape
}
// `Context` is basically `inferAsyncReturnType<typeof createContext>`
export const errorFormatter: ErrorFormatter<Context, DefaultErrorShape> = opts => {
/** do your things, maybe replace DefaultErrorShape */
return opts.shape
}
Error related types can be found in @trpc/server/dist/error/formatter I think this would be the way to extend the default error shape
import { DefaultErrorData, ErrorFormatter } from '@trpc/server/dist/error/formatter'
import { TRPCErrorShape } from '@trpc/server/dist/rpc'
import { TRPC_ERROR_CODE_NUMBER } from '@trpc/server/http'
import { typeToFlattenedError, ZodError } from 'zod'
import { Context } from './trpcCore'

interface CustomErrorShape
extends TRPCErrorShape<
TRPC_ERROR_CODE_NUMBER,
/** eslint-disable-next-line @typescript-eslint/no-explicit-any */
DefaultErrorData & { zodError: typeToFlattenedError<any, string> | null }
> {
message: string
code: TRPC_ERROR_CODE_NUMBER
}
import { DefaultErrorData, ErrorFormatter } from '@trpc/server/dist/error/formatter'
import { TRPCErrorShape } from '@trpc/server/dist/rpc'
import { TRPC_ERROR_CODE_NUMBER } from '@trpc/server/http'
import { typeToFlattenedError, ZodError } from 'zod'
import { Context } from './trpcCore'

interface CustomErrorShape
extends TRPCErrorShape<
TRPC_ERROR_CODE_NUMBER,
/** eslint-disable-next-line @typescript-eslint/no-explicit-any */
DefaultErrorData & { zodError: typeToFlattenedError<any, string> | null }
> {
message: string
code: TRPC_ERROR_CODE_NUMBER
}
More Posts
tRPC works only for monoliths environment?How can I works if typesafe in real time with a remote server? 🤔How to use createCaller() with lambda for testing?Has anyone successfully mocked a trpc caller that uses the AWS Lambda integration? trying to write sis there a way to call useQuery() from a callback and get the return value within that callback?I have a generic component that is effectively an autocomplete that fills in options from a web requUsing Response with the Next App RouterThe route handlers in the App Router, only receive the Request object, requiring you to use a ResponThe only way to access useQuery options without input is passing undefined to it?Is there any other way? seems strange pass undefined to the input queryHow can I access the trpc context in zod's refine function?To do something like ```ts create: myProcedure .input(myInputSchema.refine(async ({ slug }, ctx)Set Request Headers for individual requests?Hello everyone, I have a simple question, can you somehow add headers to the individual requests insGet undefined when the refetch function has successfully workedIn my use case, I first disabled the useQuery function because I want it only fetch when I want to. Having trouble to import my AppRouter in my react clientEnvironment: Node v18.15.0 I created my TRPC router in my express app and exported it how -documeArgument of Type not assignableSeeing the following error while trying to establish a connection with the trpc server from the clieCan't I create multiple TRPC React using same Router?Im using monorepo and have 2 client projects on that. I have 2 files that does the same, create the Types with enabled: falseHow do types work with enabled: false? Do I need to cast my arguments in the cases where enabled is