UNPKG

@yoroi/banxa

Version:

The Banxa integration package of Yoroi SDK

20 lines (19 loc) 714 B
import { BanxaUnknownError, BanxaValidationError } from './errors'; import { ZodError } from 'zod'; /** * Converts a ZodError or Error to a BanxaError. * @param error - The error to convert. * @throws An appropriate BanxaError based on zod error, or ignore it. */ export function handleZodErrors(error) { if (error instanceof ZodError) { const errorDetails = error.issues.map(e => ({ field: e.path.join('.'), message: e.message })); const errorMessage = `Invalid data: ${errorDetails.map(e => `${e.field}: ${e.message}`).join(', ')}`; throw new BanxaValidationError(errorMessage); } throw new BanxaUnknownError(JSON.stringify(error)); } //# sourceMappingURL=zod-errors.js.map