Skip to main content

Module error_formatter

Module error_formatter 

Source
Expand description

Error Formatter

This module provides error sanitization and formatting for different environments. It controls what error details are exposed to clients based on deployment context.

§Architecture

The Error Formatter acts as the fifth and final layer in the security middleware:

GraphQL Error
    ↓
ErrorFormatter::format_error()
    ├─ Check 1: Determine detail level based on environment
    ├─ Check 2: Sanitize error message
    ├─ Check 3: Remove sensitive information
    └─ Check 4: Return formatted error
    ↓
Safe Error Message (suitable for client)

§Examples

use fraiseql_core::security::{ErrorFormatter, DetailLevel};

// Create formatter for production (minimal details)
let formatter = ErrorFormatter::new(DetailLevel::Production);

// Format an error
let error_msg = "Database error: connection refused to postgresql://user:pass@db.local";
let formatted = formatter.format_error(error_msg);
println!("{}", formatted); // Shows only: "Internal server error"

Structs§

ErrorFormatter
Error Formatter
SanitizationConfig
Sanitization configuration

Enums§

DetailLevel
Detail level for error responses