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 |
#2 in #http-error
360 downloads per month
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
~56K SLoC