/** * Custom error class for B44 SDK */ export class B44Error extends Error { /** * HTTP status code */ status?: number; /** * Error code */ code?: string; /** * Additional error data */ data?: any; /** * Original error that caused this error */ originalError?: Error; /** * Create a new B44Error * @param message Error message * @param status HTTP status code * @param code Error code * @param data Additional error data * @param originalError Original error that caused this error */ constructor( message: string, status?: number, code?: string, data?: any, originalError?: Error ) { super(message); this.name = "B44Error"; this.status = status; this.code = code; this.data = data; this.originalError = originalError; } /** * Convert the error to a JSON object * @returns JSON representation of the error */ toJSON() { return { name: this.name, message: this.message, status: this.status, code: this.code, data: this.data, }; } } /** * Log an error to the console in development mode * @param prefix Prefix for the error message * @param error Error to log */ export function logError(prefix: string, error: Error | B44Error): void { if (error instanceof B44Error) { if (console.error) { console.error(`${prefix} ${error.status}: ${error.message}`); if (error.data) { try { console.error("Error data:", JSON.stringify(error.data, null, 2)); } catch (e) { console.error("Error data: [Cannot stringify error data]"); } } } } else { if (console.error) { console.error(`${prefix} ${error.message}`); } } }