Module hyper_middleware::error

source ·
Expand description

The custom error module.

This module provides a custom Error type with HTTP Status functionality as well as useful macros. The Error type implements other several common error types to ease conversions while consuming the input value via the From trait.

Additionally, when used in HTTP contexts, the Error type can be associated to an HTTP Status Code. via the Error::with_status method.

a. Construct an Error from hyper::Error, std::io::Error, anyhow::Error or an string.

use hyper_middleware::error

let err = Error::from("some error type or string");
// Or using a shortcut macro
let err = error!("some error type or string");

b. Construct an Error with an associated HTTP Status Code.

use hyper::StatusCode;
use hyper_middleware::error

let err = error!("user or password does not match").with_status(StatusCode::UNAUTHORIZED);
// Or using a shortcut macro
let err = http_error_unauthorized!("user or password does not match");

Modules

Structs

  • Represents an HTTP Error.

Traits

  • Provides the context method for Result.

Type Definitions