custom errorFormatter doesn't work for me #5555
-
Beta Was this translation helpful? Give feedback.
Answered by
KATT
Mar 10, 2024
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Follow the docs. You need to spread the incoming properties the same way the docs https://trpc.io/docs/server/error-formatting Eg import { initTRPC } from '@trpc/server';
export const t = initTRPC.context<Context>().create({
errorFormatter(opts) {
const { shape, error } = opts;
return {
...shape,
data: {
...shape.data,
zodError:
error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
? error.cause.flatten()
: null,
},
};
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
KATT
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Follow the docs. You need to spread the incoming properties the same way the docs
https://trpc.io/docs/server/error-formatting
Eg