Crates.io | http-whatever |
lib.rs | http-whatever |
version | 0.4.0 |
source | src |
created_at | 2023-11-20 12:12:33.112482 |
updated_at | 2024-10-31 16:24:31.167235 |
description | A threadsafe snafu::Whatever for HTTP errors |
homepage | https://github.com/bassmanitram/http-whatever |
repository | https://github.com/bassmanitram/http-whatever |
max_upload_size | |
id | 1042018 |
size | 25,720 |
A Thread-safe version of snafu::Whatever
,
which also allows for structured message strings giving HTTP status code and application
domain qualifiers, and allows an Error to be turned into an http::Response
.
I fully admit that this flies in the face of "type-oriented" error handling, but I really do feel that that is overkill for most HTTP applications where one error (or one error chain) is the most you will get out of any request/response cycle, and the goals are simply:
a. Tell the user what went wrong with a standard HTTP status and message, and b. Log the error (chain) for further investigation if necessary
To that end, this allows you to use the "whatever..." context features from
snafu
while still categorizing your errors and avoiding the boilerplate
of creating error HTTP responses from those errors.
use http_whatever::prelude::*;
fn parse_uint(uint_as_str: &str) -> Result<usize, HttpWhatever> {
uint_as_str.parse().whatever_context("400:RequestContent:Bad value")?
}
use http_whatever::prelude::*;
fn parse_uint(uint_as_str: &str) -> Result<usize, HttpWhatever> {
uint_as_str.parse().whatever_context(http_err!(400,uint_as_str,"Bad input"))?
}