[][src]Struct hyperdrive::Error

pub struct Error { /* fields omitted */ }

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]

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 HTTP StatusCode describing the error.
  • source: The underlying error that caused this one. Any type implementing std::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]

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 description(&self) -> &str1.0.0[src]

This method is soft-deprecated. Read more

fn cause(&self) -> Option<&dyn Error>1.0.0[src]

Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

The lower-level cause of this error, if any. Read more

Auto Trait Implementations

impl Sync for Error

impl Unpin for Error

impl Send for Error

impl !UnwindSafe for Error

impl !RefUnwindSafe for Error

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T