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
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
throw new CommerceError({
|
||||
code: 'SCHEMA_VALIDATION_ERROR',
|
||||
message:
|
||||
`The ${operation} opration returned invalid data: \n` +
|
||||
error.issues
|
||||
.map((e) => `- ${e.path.join('.')}: ${e.message}`)
|
||||
.join('\n'),
|
||||
})
|
||||
return Promise.reject(
|
||||
new CommerceError({
|
||||
code: 'SCHEMA_VALIDATION_ERROR',
|
||||
message:
|
||||
`The ${operation} opration returned invalid data and has ${
|
||||
error.issues.length
|
||||
} 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 {
|
||||
throw error
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user