| Crates.io | error_status |
| lib.rs | error_status |
| version | 0.1.0 |
| created_at | 2025-02-18 12:35:30.360379+00 |
| updated_at | 2025-02-18 12:35:30.360379+00 |
| description | Model common error context with HTTP 4xx and 5xx code |
| homepage | |
| repository | https://github.com/kanru/error_status |
| max_upload_size | |
| id | 1559857 |
| size | 26,012 |
A lightweight error handling library for Rust that combines HTTP-style error statuses with contextual information.
Result typeAdd this to your Cargo.toml:
[dependencies]
error_status = "0.1.0";
use std::io::{self, ErrorKind};
use anyhow::Result;
use error_status::ResultExt;
fn find_file() -> Result<(), io::Error> {
Err(ErrorKind::NotFound.into())
}
fn main() -> Result<()> {
find_file()
.not_found("Failed to read file")
.internal_error("Config file is not available")?;
Ok(())
}
The library provides a ResultExt trait that extends Result with methods
corresponding to common error scenarios:
not_found(): For missing resource errorsinternal_error(): For internal system errorsbad_request(): For validation failuresEach method accepts a context string that provides additional information about
the error. There's also a corresponding _lazy() version for context builder.
MIT OR Apache-2.0
Contributions are welcome! Please feel free to submit a Pull Request.