mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
21 lines
624 B
TypeScript
21 lines
624 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
|