Struct http_whatever::HttpWhatever
source · pub struct HttpWhatever { /* private fields */ }Expand description
An almost-drop-in replacement for snafu::Whatever with the following benefits:
- Conforms to the async magic incantation
Send + Sync + 'staticand so is thread-safe and async-safe - Can be transformed into an http::Response using information from the error to complete the response
- A public
newconstructor that facilitates better ergonomics in certain error situations. - A public
partsmethod to retrieve the three parts of the error.
Otherwise it is exactly the same as snafu::Whatever and can be used in exactly the same
way.
(almost-drop-in because, obviously, you have to use HttpWhatever as your error type).
Implementations§
source§impl HttpWhatever
impl HttpWhatever
sourcepub fn parts(&self) -> (&str, &str, StatusCode)
pub fn parts(&self) -> (&str, &str, StatusCode)
Return the three parts of the message as a 3-element tuple.
The three parts are
- The
messageas a string slice - the
domainas a string slice - the HTTP status code as a
http::StatusCode
This method is useful if you wish to construct a customized response from the error, but still want the categorization that this error type allows.
sourcepub fn as_http_response<B>(&self) -> Response<B>where
B: Default,
pub fn as_http_response<B>(&self) -> Response<B>where
B: Default,
Return an http::Response<B> representation of the error, with
a body generated from the default method of the generic body type.
sourcepub fn as_http_string_response<B>(&self) -> Response<B>
pub fn as_http_string_response<B>(&self) -> Response<B>
Return an http::Response<B> representation of the error, with
a string body generated from the into method of the generic body
type.
The string in the response body will be of the format
<message> (application domain: <domain>)
The content-type header of the response will be text/plain.
sourcepub fn as_http_json_response<B>(&self) -> Response<B>
pub fn as_http_json_response<B>(&self) -> Response<B>
Return an http::Response<B> representation of the error, with
a JSON body generated from the into method.
The string in the response body will be of the format
{"message":"<message>","domain":"<domain>"}
The content-type header of the response will be application/json.
Trait Implementations§
source§impl Debug for HttpWhatever
impl Debug for HttpWhatever
source§impl Display for HttpWhatever
impl Display for HttpWhatever
source§impl Error for HttpWhatever
impl Error for HttpWhatever
source§fn description(&self) -> &str
fn description(&self) -> &str
source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
source§impl ErrorCompat for HttpWhatever
impl ErrorCompat for HttpWhatever
source§fn iter_chain(&self) -> ChainCompat<'_>where
Self: AsErrorSource,
fn iter_chain(&self) -> ChainCompat<'_>where
Self: AsErrorSource,
Error::source. Read more