dev experience
This commit is contained in:
@@ -1,8 +1,33 @@
|
||||
import { ErrorReporter } from '../../interfaces/ErrorReporter';
|
||||
import { getGlobalErrorHandler } from '../GlobalErrorHandler';
|
||||
|
||||
export class ConsoleErrorReporter implements ErrorReporter {
|
||||
report(error: Error, context?: unknown): void {
|
||||
const timestamp = new Date().toISOString();
|
||||
console.error(`[${timestamp}] Error reported:`, error.message, { error, context });
|
||||
|
||||
// Use enhanced global handler if available
|
||||
try {
|
||||
const globalHandler = getGlobalErrorHandler();
|
||||
const enhancedContext: Record<string, unknown> = {
|
||||
source: 'legacy_reporter',
|
||||
timestamp,
|
||||
};
|
||||
if (typeof context === 'object' && context !== null) {
|
||||
Object.assign(enhancedContext, context);
|
||||
}
|
||||
globalHandler.report(error, enhancedContext);
|
||||
} catch {
|
||||
// Fallback to basic logging if global handler not available
|
||||
console.error(`[${timestamp}] Error reported:`, error.message, { error, context });
|
||||
|
||||
// Also log to console with enhanced format
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.groupCollapsed(`%c[LEGACY ERROR] ${error.name}: ${error.message}`, 'color: #ff6600; font-weight: bold;');
|
||||
console.log('Error:', error);
|
||||
console.log('Context:', context);
|
||||
console.log('Stack:', error.stack);
|
||||
console.groupEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user