Tend your corner of the atmosphere. spores.garden turns your AT Protocol records into a personal site with unique themes. Your data never leaves your PDS. Grow something that's truly yours. spores.garden
at main 46 lines 991 B view raw
1/** 2 * Error Handling Utilities 3 * 4 * Provides consistent error handling across the application. 5 */ 6 7/** 8 * Application error with context 9 */ 10export class AppError extends Error { 11 constructor( 12 message: string, 13 public readonly code: string, 14 public readonly context?: Record<string, unknown> 15 ) { 16 super(message); 17 this.name = 'AppError'; 18 } 19} 20 21/** 22 * Log a warning with context 23 */ 24export function logWarning(message: string, context: string, data?: unknown): void { 25 console.warn(`[${context}] ${message}`, data ?? ''); 26} 27 28/** 29 * Log an error with context 30 */ 31export function logError(message: string, context: string, error?: unknown): void { 32 console.error(`[${context}] ${message}`, error ?? ''); 33} 34 35/** 36 * Extract error message from unknown error type 37 */ 38export function getErrorMessage(error: unknown): string { 39 if (error instanceof Error) { 40 return error.message; 41 } 42 if (typeof error === 'string') { 43 return error; 44 } 45 return 'Unknown error'; 46}