mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 06:01:21 +00:00
25 lines
637 B
TypeScript
25 lines
637 B
TypeScript
import { ValidationError } from '@commerce/utils/errors'
|
|
|
|
import { CheckoutError, CheckoutErrorCode, AppError, AccountError, AccountErrorCode } from '../schema'
|
|
|
|
export type UserErrors = Array<CheckoutError | AccountError | AppError>
|
|
|
|
export type UserErrorCode =
|
|
| CheckoutErrorCode
|
|
| AccountErrorCode
|
|
| null
|
|
| undefined
|
|
|
|
export const throwUserErrors = (errors?: UserErrors) => {
|
|
if (errors && errors.length) {
|
|
throw new ValidationError({
|
|
errors: errors.map(({ code, message }) => ({
|
|
code: code ?? 'validation_error',
|
|
message: message || "",
|
|
})),
|
|
})
|
|
}
|
|
}
|
|
|
|
export default throwUserErrors
|