safeer-pdf-generator
Version:
Framework-agnostic PDF generation library with chunking, merging, S3 upload, and email delivery
137 lines • 3.59 kB
JavaScript
/**
* Base error class for PDF Reporter errors
*/
export 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}`;
}
}
}
/**
* Error thrown during PDF generation process
*/
export class PdfGenerationError extends PdfReporterError {
constructor(message, phase, cause) {
super(message, cause);
this.phase = phase;
this.code = 'PDF_GENERATION_ERROR';
}
}
/**
* Error thrown during template compilation
*/
export class TemplateError extends PdfReporterError {
constructor(message, templateName, cause) {
super(message, cause);
this.templateName = templateName;
this.code = 'TEMPLATE_ERROR';
}
}
/**
* Error thrown during S3 upload operations
*/
export class S3UploadError extends PdfReporterError {
constructor(message, bucket, key, cause) {
super(message, cause);
this.bucket = bucket;
this.key = key;
this.code = 'S3_UPLOAD_ERROR';
}
}
/**
* Error thrown during email sending operations
*/
export class EmailError extends PdfReporterError {
constructor(message, recipient, cause) {
super(message, cause);
this.recipient = recipient;
this.code = 'EMAIL_ERROR';
}
}
/**
* Error thrown during chunk processing
*/
export class ChunkProcessingError extends PdfReporterError {
constructor(message, chunkIndex, cause) {
super(message, cause);
this.chunkIndex = chunkIndex;
this.code = 'CHUNK_PROCESSING_ERROR';
}
}
/**
* Error thrown when browser operations fail
*/
export class BrowserError extends PdfReporterError {
constructor(message, operation, cause) {
super(message, cause);
this.operation = operation;
this.code = 'BROWSER_ERROR';
}
}
/**
* Error thrown during PDF merging operations
*/
export class MergeError extends PdfReporterError {
constructor(message, chunkCount, cause) {
super(message, cause);
this.chunkCount = chunkCount;
this.code = 'MERGE_ERROR';
}
}
/**
* Error thrown for configuration issues
*/
export class ConfigurationError extends PdfReporterError {
constructor(message, field, cause) {
super(message, cause);
this.field = field;
this.code = 'CONFIGURATION_ERROR';
}
}
/**
* Error thrown for timeout issues
*/
export class TimeoutError extends PdfReporterError {
constructor(message, timeoutMs, cause) {
super(message, cause);
this.timeoutMs = timeoutMs;
this.code = 'TIMEOUT_ERROR';
}
}
/**
* Type guard to check if error is a PDF Reporter error
*/
export function isPdfReporterError(error) {
return error instanceof PdfReporterError;
}
/**
* Extract meaningful error message from any error type
*/
export 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
*/
export function getErrorStack(error) {
if (error instanceof Error) {
return error.stack;
}
return undefined;
}
//# sourceMappingURL=errors.js.map