UNPKG

safeer-pdf-generator

Version:

Framework-agnostic PDF generation library with chunking, merging, S3 upload, and email delivery

153 lines 4.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeoutError = exports.ConfigurationError = exports.MergeError = exports.BrowserError = exports.ChunkProcessingError = exports.EmailError = exports.S3UploadError = exports.TemplateError = exports.PdfGenerationError = exports.PdfReporterError = void 0; exports.isPdfReporterError = isPdfReporterError; exports.getErrorMessage = getErrorMessage; exports.getErrorStack = getErrorStack; /** * Base error class for PDF Reporter errors */ class PdfReporterError extends Error { constructor(message, cause) { super(message); this.cause = cause; this.name = this.constructor.name; // Maintain proper stack trace if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } // Include cause in stack trace if available if (cause?.stack) { this.stack = `${this.stack}\nCaused by: ${cause.stack}`; } } } exports.PdfReporterError = PdfReporterError; /** * Error thrown during PDF generation process */ class PdfGenerationError extends PdfReporterError { constructor(message, phase, cause) { super(message, cause); this.phase = phase; this.code = 'PDF_GENERATION_ERROR'; } } exports.PdfGenerationError = PdfGenerationError; /** * Error thrown during template compilation */ class TemplateError extends PdfReporterError { constructor(message, templateName, cause) { super(message, cause); this.templateName = templateName; this.code = 'TEMPLATE_ERROR'; } } exports.TemplateError = TemplateError; /** * Error thrown during S3 upload operations */ class S3UploadError extends PdfReporterError { constructor(message, bucket, key, cause) { super(message, cause); this.bucket = bucket; this.key = key; this.code = 'S3_UPLOAD_ERROR'; } } exports.S3UploadError = S3UploadError; /** * Error thrown during email sending operations */ class EmailError extends PdfReporterError { constructor(message, recipient, cause) { super(message, cause); this.recipient = recipient; this.code = 'EMAIL_ERROR'; } } exports.EmailError = EmailError; /** * Error thrown during chunk processing */ class ChunkProcessingError extends PdfReporterError { constructor(message, chunkIndex, cause) { super(message, cause); this.chunkIndex = chunkIndex; this.code = 'CHUNK_PROCESSING_ERROR'; } } exports.ChunkProcessingError = ChunkProcessingError; /** * Error thrown when browser operations fail */ class BrowserError extends PdfReporterError { constructor(message, operation, cause) { super(message, cause); this.operation = operation; this.code = 'BROWSER_ERROR'; } } exports.BrowserError = BrowserError; /** * Error thrown during PDF merging operations */ class MergeError extends PdfReporterError { constructor(message, chunkCount, cause) { super(message, cause); this.chunkCount = chunkCount; this.code = 'MERGE_ERROR'; } } exports.MergeError = MergeError; /** * Error thrown for configuration issues */ class ConfigurationError extends PdfReporterError { constructor(message, field, cause) { super(message, cause); this.field = field; this.code = 'CONFIGURATION_ERROR'; } } exports.ConfigurationError = ConfigurationError; /** * Error thrown for timeout issues */ class TimeoutError extends PdfReporterError { constructor(message, timeoutMs, cause) { super(message, cause); this.timeoutMs = timeoutMs; this.code = 'TIMEOUT_ERROR'; } } exports.TimeoutError = TimeoutError; /** * Type guard to check if error is a PDF Reporter error */ function isPdfReporterError(error) { return error instanceof PdfReporterError; } /** * Extract meaningful error message from any error type */ function getErrorMessage(error) { if (error instanceof Error) { return error.message; } if (typeof error === 'string') { return error; } return 'Unknown error occurred'; } /** * Extract error stack trace safely */ function getErrorStack(error) { if (error instanceof Error) { return error.stack; } return undefined; } //# sourceMappingURL=errors.js.map