Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heat1q/anyhow-http
Customizable Http errors built on anyhow
https://github.com/heat1q/anyhow-http
Last synced: about 5 hours ago
JSON representation
Customizable Http errors built on anyhow
- Host: GitHub
- URL: https://github.com/heat1q/anyhow-http
- Owner: heat1q
- License: mit
- Created: 2023-11-24T17:31:19.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-02T09:34:49.000Z (4 months ago)
- Last Synced: 2025-01-09T11:49:14.329Z (4 days ago)
- Language: Rust
- Size: 104 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# anyhow-http
`anyhow-http` offers customizable HTTP errors built on [`anyhow`](https://docs.rs/prometheus/latest/prometheus/) errors. This crates acts as a superset of [`anyhow`](https://docs.rs/prometheus/latest/prometheus/), extending the functionality to define custom HTTP error responses.
## Example
```rust
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 {
fallible_operation()?;
Ok(())
}
```## License
Licensed under [MIT](https://github.com/heat1q/anyhow-http/blob/master/LICENSE).