[−][src]Struct hyperdrive::Error
The error type used by the Hyperdrive library.
This type can be turned into an HTTP response and sent back to a client.
Methods
impl Error
[src]
pub fn from_status(status: StatusCode) -> Self
[src]
Creates an error that contains just the given StatusCode
.
Panics
This will panic when called with a status
that does not indicate a
client or server error.
pub fn with_source<S>(status: StatusCode, source: S) -> Self where
S: Into<BoxedError>,
[src]
S: Into<BoxedError>,
Creates an error from an HTTP error code and an underlying error that caused this one.
Responding with the returned Error
will not send a response body back
to the client.
Parameters
status
: The HTTPStatusCode
describing the error.source
: The underlying error that caused this one. Any type implementingstd::error::Error + Send + Sync
can be passed here.
Panics
This will panic when called with a status
that does not indicate a
client or server error.
pub fn wrong_method<M>(allowed_methods: M) -> Self where
M: Into<Cow<'static, [&'static Method]>>,
[src]
M: Into<Cow<'static, [&'static Method]>>,
Creates an error with status code 405 Method Not Allowed
and includes
the allowed set of HTTP methods.
This is called by the code generated by #[derive(FromRequest)]
and
usually does not need to be called by the user (it may be difficult to
determine the full set of allowed methods for a given path).
Calling Error::response
on the error created by this function will
automatically include an Allow
header listing all allowed methods.
Including this header is required by RFC 7231.
Parameters
allowed_methods
: The list of allowed HTTP methods for the path in the request. This can be empty, but usually should contain at least one method.
pub fn http_status(&self) -> StatusCode
[src]
Returns the HTTP status code that describes this error.
pub fn response(&self) -> Response<()>
[src]
Creates an HTTP response for indicating this error to the client.
No body will be provided (hence the ()
body type), but the caller can
map
the result to supply one.
Example
Call map
on the response to supply your own HTTP payload:
use http::StatusCode; use hyper::Body; let error = Error::from_status(StatusCode::NOT_FOUND); let response = error.response() .map(|()| Body::from("oh no!"));
pub fn allowed_methods(&self) -> Option<&[&'static Method]>
[src]
If self
is a 405 Method Not Allowed
error, returns the list of
allowed methods.
Returns None
if self
is a different kind of error.
Trait Implementations
impl Debug for Error
[src]
impl Display for Error
[src]
impl Error for Error
[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
[src]
fn description(&self) -> &str
1.0.0[src]
This method is soft-deprecated. Read more
fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
Auto Trait Implementations
impl Unpin for Error
impl Sync for Error
impl Send for Error
impl !UnwindSafe for Error
impl !RefUnwindSafe for Error
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,