UNPKG

@454creative/easy-email

Version:

A framework-agnostic email service library for Node.js with observability and monitoring

140 lines 5.14 kB
"use strict"; /** * Custom error classes for email service */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SpamDetectionError = exports.QuotaExceededError = exports.ConnectionError = exports.TemplateNotFoundError = exports.InvalidTemplateError = exports.MissingRequiredFieldError = exports.InvalidEmailError = exports.NetworkError = exports.AuthenticationError = exports.RateLimitError = exports.TimeoutError = exports.RetryError = exports.TemplateError = exports.ValidationError = exports.ProviderError = exports.ConfigurationError = exports.EmailServiceError = void 0; class EmailServiceError extends Error { constructor(message, code, details) { super(message); this.name = 'EmailServiceError'; this.code = code; this.details = details; this.timestamp = new Date(); } } exports.EmailServiceError = EmailServiceError; class ConfigurationError extends EmailServiceError { constructor(message, details) { super(message, 'CONFIG_ERROR', details); this.name = 'ConfigurationError'; } } exports.ConfigurationError = ConfigurationError; class ProviderError extends EmailServiceError { constructor(message, provider, details) { super(message, 'PROVIDER_ERROR', details); this.name = 'ProviderError'; this.provider = provider; } } exports.ProviderError = ProviderError; class ValidationError extends EmailServiceError { constructor(message, details) { super(message, 'VALIDATION_ERROR', details); this.name = 'ValidationError'; } } exports.ValidationError = ValidationError; class TemplateError extends EmailServiceError { constructor(message, details) { super(message, 'TEMPLATE_ERROR', details); this.name = 'TemplateError'; } } exports.TemplateError = TemplateError; class RetryError extends EmailServiceError { constructor(message, retryCount, maxRetries, details) { super(message, 'RETRY_ERROR', details); this.name = 'RetryError'; this.retryCount = retryCount; this.maxRetries = maxRetries; } } exports.RetryError = RetryError; class TimeoutError extends EmailServiceError { constructor(message, timeoutMs, details) { super(message, 'TIMEOUT_ERROR', details); this.name = 'TimeoutError'; this.timeoutMs = timeoutMs; } } exports.TimeoutError = TimeoutError; class RateLimitError extends EmailServiceError { constructor(message, retryAfter, details) { super(message, 'RATE_LIMIT_ERROR', details); this.name = 'RateLimitError'; this.retryAfter = retryAfter; } } exports.RateLimitError = RateLimitError; class AuthenticationError extends EmailServiceError { constructor(message, details) { super(message, 'AUTH_ERROR', details); this.name = 'AuthenticationError'; } } exports.AuthenticationError = AuthenticationError; class NetworkError extends EmailServiceError { constructor(message, statusCode, details) { super(message, 'NETWORK_ERROR', details); this.name = 'NetworkError'; this.statusCode = statusCode; } } exports.NetworkError = NetworkError; class InvalidEmailError extends ValidationError { constructor(email, details) { super(`Invalid email address: ${email}`, details); this.name = 'InvalidEmailError'; } } exports.InvalidEmailError = InvalidEmailError; class MissingRequiredFieldError extends ValidationError { constructor(field, details) { super(`Missing required field: ${field}`, details); this.name = 'MissingRequiredFieldError'; } } exports.MissingRequiredFieldError = MissingRequiredFieldError; class InvalidTemplateError extends TemplateError { constructor(template, details) { super(`Invalid template: ${template}`, details); this.name = 'InvalidTemplateError'; } } exports.InvalidTemplateError = InvalidTemplateError; class TemplateNotFoundError extends TemplateError { constructor(template, details) { super(`Template not found: ${template}`, details); this.name = 'TemplateNotFoundError'; } } exports.TemplateNotFoundError = TemplateNotFoundError; class ConnectionError extends EmailServiceError { constructor(message, provider, details) { super(message, 'CONNECTION_ERROR', details); this.name = 'ConnectionError'; this.provider = provider; } } exports.ConnectionError = ConnectionError; class QuotaExceededError extends EmailServiceError { constructor(message, quota, limit, used, details) { super(message, 'QUOTA_EXCEEDED_ERROR', details); this.name = 'QuotaExceededError'; this.quota = quota; this.limit = limit; this.used = used; } } exports.QuotaExceededError = QuotaExceededError; class SpamDetectionError extends EmailServiceError { constructor(message, reason, details) { super(message, 'SPAM_DETECTION_ERROR', details); this.name = 'SpamDetectionError'; this.reason = reason; } } exports.SpamDetectionError = SpamDetectionError; //# sourceMappingURL=index.js.map