UNPKG

vies-checker

Version:

Modern European VIES VAT number validator with full TypeScript support

47 lines 1.28 kB
/** * Custom error class for VIES API errors * * @example * ```typescript * try { * const result = await checkVAT('LU', '26375245'); * } catch (error) { * if (error instanceof ViesError) { * console.log(error.code); // 'TIMEOUT', 'SERVICE_UNAVAILABLE', etc. * if (error.isTransient()) { * // Retry logic * } * } * } * ``` */ export class ViesError extends Error { /** * The VIES error code */ code; constructor(code, message) { super(message || code); this.name = 'ViesError'; this.code = code; // Restore prototype chain for instanceof checks Object.setPrototypeOf(this, ViesError.prototype); } /** * Check if error represents a rate limit * @returns true if the error is a rate limit error */ isRateLimitError() { return this.code === 'GLOBAL_MAX_CONCURRENT_REQ' || this.code === 'MS_MAX_CONCURRENT_REQ'; } /** * Check if error might be transient and worth retrying * @returns true if the error is likely temporary */ isTransient() { return (this.code === 'SERVICE_UNAVAILABLE' || this.code === 'MS_UNAVAILABLE' || this.code === 'TIMEOUT'); } } //# sourceMappingURL=errors.js.map