UNPKG

@mirad-work/sms-core

Version:

A framework-agnostic TypeScript SMS service core with provider abstraction for Iranian SMS providers

91 lines 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpException = exports.RateLimitException = exports.MessageValidationException = exports.MissingConfigException = exports.ConfigurationException = exports.SmsDriverException = exports.UnsupportedDriverException = exports.SmsException = void 0; /** * Base SMS exception class */ class SmsException extends Error { constructor(message, _originalError, _code) { super(message); this._originalError = _originalError; this._code = _code; this.name = "SmsException"; // Maintains proper stack trace for where our error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, SmsException); } } } exports.SmsException = SmsException; /** * Exception thrown when an unsupported driver is requested */ class UnsupportedDriverException extends SmsException { constructor(driver) { super(`Unsupported SMS driver: ${driver}`, undefined, "UNSUPPORTED_DRIVER"); this.name = "UnsupportedDriverException"; } } exports.UnsupportedDriverException = UnsupportedDriverException; /** * Exception thrown when a driver encounters an error */ class SmsDriverException extends SmsException { constructor(message, originalError, code) { super(message, originalError, code); this.name = "SmsDriverException"; } } exports.SmsDriverException = SmsDriverException; /** * Exception thrown when configuration is invalid */ class ConfigurationException extends SmsException { constructor(message, code) { super(message, undefined, code); this.name = "ConfigurationException"; } } exports.ConfigurationException = ConfigurationException; /** * Exception thrown when required configuration is missing */ class MissingConfigException extends ConfigurationException { constructor(missingKey) { super(`Missing required configuration: ${missingKey}`, "MISSING_CONFIG"); this.name = "MissingConfigException"; } } exports.MissingConfigException = MissingConfigException; /** * Exception thrown when message validation fails */ class MessageValidationException extends SmsException { constructor(message, code) { super(message, undefined, code); this.name = "MessageValidationException"; } } exports.MessageValidationException = MessageValidationException; /** * Exception thrown when rate limit is exceeded */ class RateLimitException extends SmsException { constructor(message = "Rate limit exceeded") { super(message, undefined, "RATE_LIMIT_EXCEEDED"); this.name = "RateLimitException"; } } exports.RateLimitException = RateLimitException; /** * Exception thrown when HTTP request fails */ class HttpException extends SmsException { constructor(message, _status, _originalError) { super(message, _originalError, "HTTP_ERROR"); this._status = _status; this.name = "HttpException"; } } exports.HttpException = HttpException; //# sourceMappingURL=sms-exceptions.js.map