7 unstable releases

0.4.0 Oct 31, 2024
0.3.1 Jul 19, 2024
0.3.0 Jan 10, 2024
0.2.1 Dec 14, 2023
0.1.1 Nov 20, 2023

#327 in HTTP server

Download history 6/week @ 2024-08-09 4/week @ 2024-08-16 2/week @ 2024-09-06 40/week @ 2024-09-13 54/week @ 2024-09-20 33/week @ 2024-09-27 20/week @ 2024-10-04 34/week @ 2024-10-11 2/week @ 2024-10-18 83/week @ 2024-10-25 85/week @ 2024-11-01 66/week @ 2024-11-08 31/week @ 2024-11-15 10/week @ 2024-11-22

267 downloads per month

Apache-2.0

14KB
144 lines

http-whatever

CI

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.

Examples

Basic use ala snafu::Whatever.

use http_whatever::prelude::*;
fn parse_uint(uint_as_str: &str) -> Result<usize, HttpWhatever> {
    uint_as_str.parse().whatever_context("400:RequestContent:Bad value")?
}

Using the macro

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"))?
}

Dependencies

~0.9–1.4MB
~28K SLoC