Trait IntoErrorResponseContext

Source
pub trait IntoErrorResponseContext {
    // Required method
    fn into_response_context(self) -> ErrorResponseContext;
}
Expand description

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

This trait allows error types to be converted into a standardized context that contains status code, error code, and message information. This context can then be used by custom error response functions to generate appropriate HTTP responses.

§Example Implementation

use axum_error_handler::{IntoErrorResponseContext, ErrorResponseContext};
 
struct MyError {
    message: String,
}
 
impl IntoErrorResponseContext for MyError {
    fn into_response_context(self) -> ErrorResponseContext {
        ErrorResponseContext::builder()
            .status_code(400)
            .code("MY_ERROR".to_string())
            .message(self.message)
            .build()
    }
}

Required Methods§

Source

fn into_response_context(self) -> ErrorResponseContext

Converts the error into an ErrorResponseContext.

Implementors§