vies-checker
Version:
Modern European VIES VAT number validator with full TypeScript support
47 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViesError = void 0;
/**
* 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
* }
* }
* }
* ```
*/
class ViesError extends Error {
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');
}
}
exports.ViesError = ViesError;
//# sourceMappingURL=errors.js.map