#error-http #anyhow #http #error #http-errors

anyhow-http

Customizable HTTP errors built on anyhow

7 unstable releases

new 0.4.3 Apr 30, 2025
0.4.2 Feb 3, 2025
0.4.1 Jan 30, 2025
0.4.0 Sep 2, 2024
0.1.0 Nov 27, 2023

#636 in Rust patterns

Download history 93/week @ 2025-01-10 38/week @ 2025-01-17 122/week @ 2025-01-24 355/week @ 2025-01-31 155/week @ 2025-02-07 137/week @ 2025-02-14 51/week @ 2025-02-21 79/week @ 2025-02-28 86/week @ 2025-03-07 69/week @ 2025-03-14 96/week @ 2025-03-21 218/week @ 2025-03-28 56/week @ 2025-04-04 174/week @ 2025-04-11 79/week @ 2025-04-18 217/week @ 2025-04-25

557 downloads per month

MIT license

34KB
698 lines

anyhow-http



anyhow-http offers customizable HTTP errors built on anyhow errors. This crates acts as a superset of anyhow, extending the functionality to define custom HTTP error responses.

Example

use axum::{
   routing::get,
   response::IntoResponse,
   Router,
};
use anyhow_http::{http_error_ret, response::Result};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(handler));

    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();
    axum::serve(listener, app).await.unwrap();
}

fn fallible_operation() -> Result<()> {
    http_error_ret!(INTERNAL_SERVER_ERROR, "this is an error")
}

async fn handler() -> Result<impl IntoResponse> {
    fallible_operation()?;
    Ok(())
}

License

Licensed under MIT.

Dependencies

~1.3–2.7MB
~54K SLoC