mirror of
https://github.com/vercel/commerce.git
synced 2025-06-08 01:06:59 +00:00
Update with-schema-parser.ts
This commit is contained in:
parent
8ad6d26833
commit
163a22ec88
@ -17,16 +17,25 @@ export const withSchemaParser =
|
|||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof z.ZodError) {
|
if (error instanceof z.ZodError) {
|
||||||
throw new CommerceError({
|
return Promise.reject(
|
||||||
code: 'SCHEMA_VALIDATION_ERROR',
|
new CommerceError({
|
||||||
message:
|
code: 'SCHEMA_VALIDATION_ERROR',
|
||||||
`The ${operation} opration returned invalid data: \n` +
|
message:
|
||||||
error.issues
|
`The ${operation} opration returned invalid data and has ${
|
||||||
.map((e) => `- ${e.path.join('.')}: ${e.message}`)
|
error.issues.length
|
||||||
.join('\n'),
|
} parse ${error.issues.length === 1 ? 'error' : 'errors'}: \n` +
|
||||||
})
|
error.issues
|
||||||
|
.map(
|
||||||
|
(e, index) =>
|
||||||
|
`${index + 1}. Property ${e.path.join('.')} (${e.code}): ${
|
||||||
|
e.message
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
.join('\n'),
|
||||||
|
})
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
throw error
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user