Wire/server: pretty-print server-side Zod errors in return messages #851

This commit is contained in:
Enrico Ros
2025-10-20 14:43:14 -07:00
parent 7c1f30c3c7
commit a4516b5fa6
+6
View File
@@ -1,3 +1,5 @@
import * as z from 'zod/v4';
/// set this to true to see the tRPC and fetch requests made by the server
export const SERVER_DEBUG_WIRE = false; //
@@ -56,6 +58,10 @@ export function safeErrorString(error: any): string | null {
return `AggregateError: ${errors.join('; ')}`;
}
// handle zod v4 errors
if (error instanceof z.ZodError)
return z.prettifyError(error);
// descend into an 'error' object
if (error.error)
return safeErrorString(error.error);