Skip to content

heat1q/anyhow-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Customizable Http errors built on anyhow

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages