Crate axum_err_handler_ctx

Source
Expand description

§Error Response Context

This module provides types and traits for creating standardized error response contexts that can be used with custom error response functions in the Axum Error Handler crate.

The main purpose is to allow custom error response functions to receive structured error information (status code, error code, message) that can be used to generate custom response formats while maintaining consistency with the error handling system.

§Example Usage

use axum_error_handler::ErrorResponseContext;
use axum::response::Response;
 
fn custom_error_handler(ctx: ErrorResponseContext) -> Response {
    // Access error information
    let status = ctx.status_code().unwrap_or(500);
    let code = ctx.code().unwrap_or(&"UNKNOWN".to_string());
    let message = ctx.message().unwrap_or(&"Error occurred".to_string());
     
    // Create custom response format
    Response::builder()
        .status(status)
        .body(format!("Error {}: {}", code, message).into())
        .unwrap()
}

Structs§

ErrorResponseBuilder
A builder for constructing ErrorResponseContext instances.
ErrorResponseContext
A structured context containing error information for generating HTTP responses.

Traits§

IntoErrorResponseContext
A trait for converting error types into structured error response contexts.