@aidalinfo/office-to-markdown
Version:
Modern TypeScript library for converting Office documents (DOCX) to Markdown format, optimized for Bun runtime with enhanced table support and math equation conversion.
83 lines • 3.13 kB
TypeScript
/**
* Comprehensive error handling utilities for the office-to-markdown library
*/
/**
* Error codes for different types of failures
*/
export declare enum ErrorCode {
FILE_NOT_FOUND = "FILE_NOT_FOUND",
FILE_ACCESS_DENIED = "FILE_ACCESS_DENIED",
FILE_CORRUPTED = "FILE_CORRUPTED",
FILE_TOO_LARGE = "FILE_TOO_LARGE",
UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT",
INVALID_FILE_STRUCTURE = "INVALID_FILE_STRUCTURE",
MISSING_DEPENDENCY = "MISSING_DEPENDENCY",
DEPENDENCY_VERSION_MISMATCH = "DEPENDENCY_VERSION_MISMATCH",
CONVERSION_FAILED = "CONVERSION_FAILED",
HTML_PARSING_FAILED = "HTML_PARSING_FAILED",
MARKDOWN_GENERATION_FAILED = "MARKDOWN_GENERATION_FAILED",
PREPROCESSING_FAILED = "PREPROCESSING_FAILED",
NETWORK_ERROR = "NETWORK_ERROR",
TIMEOUT_ERROR = "TIMEOUT_ERROR",
UNKNOWN_ERROR = "UNKNOWN_ERROR",
INVALID_INPUT = "INVALID_INPUT"
}
/**
* Enhanced error class with error codes and context
*/
export declare class OfficeToMarkdownError extends Error {
readonly code: ErrorCode;
readonly context?: Record<string, any>;
readonly originalError?: Error;
constructor(message: string, code?: ErrorCode, context?: Record<string, any>, originalError?: Error);
/**
* Convert to JSON for logging or API responses
*/
toJSON(): Record<string, any>;
}
/**
* Error handler utility class
*/
export declare class ErrorHandler {
/**
* Wrap a function with error handling
*/
static wrapAsync<T>(fn: () => Promise<T>, errorContext?: Record<string, any>): Promise<T>;
/**
* Wrap a synchronous function with error handling
*/
static wrap<T>(fn: () => T, errorContext?: Record<string, any>): T;
/**
* Enhance an error with additional context and proper error codes
*/
static enhanceError(error: unknown, context?: Record<string, any>): OfficeToMarkdownError;
/**
* Attempt to determine error code from error message
*/
private static getErrorCodeFromMessage;
/**
* Create a file-related error
*/
static createFileError(filePath: string, originalError: Error, operation?: string): OfficeToMarkdownError;
/**
* Create a conversion-specific error
*/
static createConversionError(phase: "preprocessing" | "docx-to-html" | "html-to-markdown" | "unknown", originalError: Error, context?: Record<string, any>): OfficeToMarkdownError;
/**
* Log error with appropriate level
*/
static logError(error: OfficeToMarkdownError | Error, logger?: any): void;
/**
* Check if error is recoverable (e.g., retry might help)
*/
static isRecoverable(error: OfficeToMarkdownError | Error): boolean;
/**
* Get user-friendly error message
*/
static getUserFriendlyMessage(error: OfficeToMarkdownError | Error): string;
}
/**
* Decorator for automatic error handling (if decorators are enabled)
*/
export declare function handleErrors(errorContext?: Record<string, any>): (target: any, propertyName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
//# sourceMappingURL=error-handler.d.ts.map