Struct Error

pub struct Error { /* private fields */ }

Represents errors that can occur handling HTTP streams.

Formatting

The Display implementation of this type will only print the details of this level of error, even though it may have been caused by another error and contain that error in its source. To print all the relevant information, including the source chain, using something like std::error::Report, or equivalent 3rd party types.

The contents of the formatted error message of this specific Error type is unspecified. You must not depend on it. The wording and details may change in any version, with the goal of improving error messages.

Source

A hyper::Error may be caused by another error. To aid in debugging, those are exposed in Error::source() as erased types. While it is possible to check the exact type of the sources, they can not be depended on. They may come from private internal dependencies, and are subject to change at any moment.

Implementations

impl Error

fn is_parse(&self) -> bool

Returns true if this was an HTTP parse error.

This can be caused by a malformed HTTP message, an invalid header, an invalid URI, an invalid HTTP version, or a message head that is too large. Use the more specific is_parse_* methods to determine the exact cause.

fn is_parse_too_large(&self) -> bool

Returns true if this was an HTTP parse error caused by a message that was too large.

This is triggered when the message head (request line plus headers for HTTP/1, or header frame for HTTP/2) exceeds the configured max_buf_size. It also covers the case where the URI alone exceeds the internal maximum URI length.

fn is_parse_status(&self) -> bool

Returns true if this was an HTTP parse error caused by an invalid response status code or reason phrase.

fn is_parse_version_h2(&self) -> bool

Returns true if this was an HTTP parse error caused by HTTP2 preface sent over an HTTP1 connection.

This can happen when a client sends an HTTP/2 connection preface to a server that is only expecting HTTP/1.x requests.

fn is_user(&self) -> bool

Returns true if this error was caused by user code.

For example, this can be returned when the user's Service returns an error, the user's Body stream yields an error, or the user sends an unexpected header combination (such as both content-length and transfer-encoding).

fn is_canceled(&self) -> bool

Returns true if this was about a Request that was canceled.

This typically happens when a pending request is dropped before it can be dispatched to the connection, for example because the connection was not ready.

fn is_closed(&self) -> bool

Returns true if a sender's channel is closed.

This can occur when the other side of a client or body channel has been dropped, indicating that the receiver is no longer interested in the data.

fn is_incomplete_message(&self) -> bool

Returns true if the connection closed before a message could complete.

This means that the supplied IO connection reported EOF (closed) while hyper's HTTP state indicates more of the message (either request or response) needed to be transmitted.

Some cases this could happen (not exhaustive):

  • A request is written on a connection, and the next read reports EOF (perhaps a server just closed an "idle" connection).
  • A message body is only partially receive before the connection reports EOF.
  • A client writes a request to your server, and then closes the write half while waiting for your response. If you need to support this, consider enabling half_close.
fn is_body_write_aborted(&self) -> bool

Returns true if the body write was aborted.

This occurs when the user's code explicitly aborts writing of the outgoing body before it completes, for example by dropping the body sender.

fn is_shutdown(&self) -> bool

Returns true if the error was caused while calling AsyncWrite::shutdown().

This can happen when the connection is being gracefully shut down and the underlying IO reports an error during the shutdown sequence.

fn is_timeout(&self) -> bool

Returns true if the error was caused by a timeout.

For HTTP/1 servers, this includes the header read timeout (see header_read_timeout). It also covers any timeout set via a user-provided timer.

Trait Implementations

impl Debug for Error

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Display for Error

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Error for Error

fn source(&self) -> Option<&dyn StdError + 'static>

Auto Trait Implementations

impl !RefUnwindSafe for Error

impl !UnwindSafe for Error

impl Freeze for Error

impl Send for Error

impl Sync for Error

impl Unpin for Error

impl UnsafeUnpin for Error

Blanket Implementations

impl<T> Any for Error where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Error where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Error where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for Error

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Error

impl<T> ToString for Error where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T> WithSubscriber for Error

impl<T, U> Into<U> for Error where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Error where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Error where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>