#error-handler #axum #web-framework #handler

axum-err-handler-ctx

A context of error that actual implement IntoResponse trait

1 unstable release

Uses new Rust 2024

0.1.0 Jul 5, 2025

#1609 in HTTP server

Download history 8/week @ 2025-07-10 1/week @ 2025-07-17 8/week @ 2025-07-24 2/week @ 2025-08-14 11/week @ 2025-08-21 1/week @ 2025-08-28 1/week @ 2025-09-04 1/week @ 2025-09-11 1/week @ 2025-09-18 8/week @ 2025-09-25 8/week @ 2025-10-09 64/week @ 2025-10-16 2/week @ 2025-10-23

74 downloads per month
Used in axum-error-handler

MIT license

12KB
100 lines

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()
}

Dependencies

~4.5–8.5MB
~150K SLoC