server: improve error formatting, removing unneeded stacks

This commit is contained in:
Enrico Ros
2025-10-23 18:07:16 -07:00
parent 12aa812b37
commit c11684a9cf
+5 -1
View File
@@ -48,10 +48,14 @@ const t = initTRPC.context<typeof createTRPCFetchContext>().create({
// server transformer - serialize: -> client, deserialize: <- client
transformer: transformer,
errorFormatter({ shape, error }) {
// Important: remove the 'stack' from the error data to avoid leaking internals and shorten the payload
const { stack, ...nonStackData } = shape.data;
return {
...shape,
data: {
...shape.data,
...nonStackData,
zodError:
error.cause instanceof z.ZodError ? z.treeifyError(error.cause) : null,
},