Expand description
Error type expected to be returned by endpoints.
It can represent an HTTP level error which is useful for helper functions
that wish to cause an early return from a handler (using the question mark operator).
It can also represent any other kind of error (using the anyhow::Error
type). These
errors are logged (if you enable the logging filter) and converted to a 500 Internal Server Error
with no other details.
HTTP level error should be created with the http
methods (which accepts a Responder
rather than
just Response
) and Internal errors should be created with the From
/Into
implementation.
Variants
Http(Response)
An error that should get returned to the client
Internal(Error)
Internal errors, reported as 500 Internal Server Error and logged locally
Implementations
sourceimpl Error
impl Error
sourcepub fn http(resp: impl Responder) -> Self
pub fn http(resp: impl Responder) -> Self
Create an Error from a Responder
- the Responder
will be converted to a response
and returned to the HTTP Client exactly the same way as an Result::Ok
would be.
This is useful in conjunction with the ?
operator for early returns.
sourcepub fn bad_request(resp: impl Responder) -> Self
pub fn bad_request(resp: impl Responder) -> Self
Create a 400 Bad Request Error from a Responder
- this method is similar to Error::http
but it also sets the status code