Function register_error_hook

Source
pub fn register_error_hook(callback: fn(ErrorContext<'_>))
Expand description

Register a callback function to be called when errors are created

ยงExample

use error_forge::{AppError, macros::{register_error_hook, ErrorLevel, ErrorContext}};
 
// Setup logging with different levels
register_error_hook(|ctx| {
    match ctx.level {
        ErrorLevel::Debug => println!("DEBUG: {} ({})", ctx.caption, ctx.kind),
        ErrorLevel::Info => println!("INFO: {} ({})", ctx.caption, ctx.kind),
        ErrorLevel::Warning => println!("WARNING: {} ({})", ctx.caption, ctx.kind),
        ErrorLevel::Error => println!("ERROR: {} ({})", ctx.caption, ctx.kind),
        ErrorLevel::Critical => println!("CRITICAL: {} ({})", ctx.caption, ctx.kind),
    }
     
    // Optional: send notifications for critical errors
    if ctx.level == ErrorLevel::Critical || ctx.is_fatal {
        // send_notification("Critical error occurred", ctx.caption);
    }
});