#error-response #http-response #error #http #http-errors

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

#1 in #http-error

Download history 119/week @ 2024-07-25 67/week @ 2024-08-01 53/week @ 2024-08-08 64/week @ 2024-08-15 185/week @ 2024-08-22 272/week @ 2024-08-29 207/week @ 2024-09-05 16/week @ 2024-09-12 68/week @ 2024-09-19 124/week @ 2024-09-26 79/week @ 2024-10-03 116/week @ 2024-10-10 85/week @ 2024-10-17 105/week @ 2024-10-24 74/week @ 2024-10-31 46/week @ 2024-11-07

324 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.4–2.8MB
~55K SLoC