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 as well
to ease conversion 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, 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, http_error_unauthorized};
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§
- macros
- Macros that provide several facilities for working with HTTP response errors or error casting.
Structs§
- Error
- Represents an HTTP Error.
Traits§
- Context
- Provides the
context
method forResult
.
Type Aliases§
- Result
Result<T, Error>