#error-response #http-response #error #http #customizable #axum #built

anyhow-http

Customizable HTTP errors built on anyhow

5 releases (3 breaking)

0.4.0 Sep 2, 2024
0.4.0-rc.1 May 23, 2024
0.3.0 Mar 12, 2024
0.2.0 Jan 3, 2024
0.1.0 Nov 27, 2023

#16 in #error-response

Download history 13/week @ 2024-09-14 95/week @ 2024-09-21 99/week @ 2024-09-28 145/week @ 2024-10-05 68/week @ 2024-10-12 104/week @ 2024-10-19 63/week @ 2024-10-26 101/week @ 2024-11-02 57/week @ 2024-11-09 56/week @ 2024-11-16 32/week @ 2024-11-23 32/week @ 2024-11-30 88/week @ 2024-12-07 38/week @ 2024-12-14 8/week @ 2024-12-21

143 downloads per month

MIT license

32KB
646 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
~55K SLoC