Skip to content

Commit 1ca5e84

Browse files
author
mozmo15
committed
fix(server): prioritize zod issues and format them
1 parent fe9c07b commit 1ca5e84

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/server/zod-compat.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,18 @@ export function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | un
195195
*/
196196
export function getParseErrorMessage(error: unknown): string {
197197
if (error && typeof error === 'object') {
198+
// When present, prioritize zod issues and format as a message and path
199+
if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) {
200+
return error.issues
201+
.map((i: { message: string; path?: string[] }) =>
202+
Array.isArray(i.path) ? `${i.message} at ${i.path.length ? 'path ' + i.path.join('.') : 'object root'}` : i.message
203+
)
204+
.join('\n');
205+
}
198206
// Try common error structures
199207
if ('message' in error && typeof error.message === 'string') {
200208
return error.message;
201209
}
202-
if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) {
203-
const firstIssue = error.issues[0];
204-
if (firstIssue && typeof firstIssue === 'object' && 'message' in firstIssue) {
205-
return String(firstIssue.message);
206-
}
207-
}
208210
// Fallback: try to stringify the error
209211
try {
210212
return JSON.stringify(error);

0 commit comments

Comments
 (0)