Update with-schema-parser.ts

This commit is contained in:
Catalin Pinte 2022-09-07 12:04:27 +03:00
parent 8ad6d26833
commit 163a22ec88

View File

@ -17,16 +17,25 @@ export const withSchemaParser =
return result
} catch (error) {
if (error instanceof z.ZodError) {
throw new CommerceError({
return Promise.reject(
new CommerceError({
code: 'SCHEMA_VALIDATION_ERROR',
message:
`The ${operation} opration returned invalid data: \n` +
`The ${operation} opration returned invalid data and has ${
error.issues.length
} parse ${error.issues.length === 1 ? 'error' : 'errors'}: \n` +
error.issues
.map((e) => `- ${e.path.join('.')}: ${e.message}`)
.map(
(e, index) =>
`${index + 1}. Property ${e.path.join('.')} (${e.code}): ${
e.message
}`
)
.join('\n'),
})
)
} else {
throw error
return Promise.reject(error)
}
}
}