Crate http_whatever

source ·
Expand description

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 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:

  • Tell the user what went wrong with a standard HTTP status and message, and
  • 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.

The message string is comprised of three colon-separated fields, with the first two being optional:

  • The HTTP status code - the default is 500
  • An arbitrary string denoting the ‘domain’ of the application that emitted the error. The significance of this is application-specific and no formatting rules are enforced for it (except that it cannot contain a colon). The default is “unknown”, which is applied when the field is missing or when it contains the empty string.
  • The message


§Basic use ala snafu::Whatever.

use http_whatever::prelude::*;
fn parse_uint(uint_as_str: &str) -> Result<usize, HttpWhatever> {
    uint_as_str.parse::<usize>().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"))


  • A prelude of the main items required to use this type effectively.


  • A macro to help format the standard message strings used by this error type.