//! Error and Result module. use std::error::Error as StdError; use std::fmt;
/// Result type often returned from methods that can have hyper `Error`s. pubtype Result<T> = std::result::Result<T, Error>;
type Cause = Box<dyn StdError + Send + Sync>;
/// 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. pubstruct Error {
inner: Box<ErrorImpl>,
}
#[derive(Debug)] pub(super) enum User { /// Error calling user's Body::poll_data(). #[cfg(all(
any(feature = "client", feature = "server"),
any(feature = "http1", feature = "http2")
))]
Body, /// The user aborted writing of the outgoing body. #[cfg(any(
all(feature = "http1", any(feature = "client", feature = "server")),
feature = "ffi"
))]
BodyWriteAborted, /// User tried to send a connect request with a nonzero body #[cfg(all(feature = "client", feature = "http2"))]
InvalidConnectWithBody, /// Error from future of user's Service. #[cfg(any(
all(any(feature = "client", feature = "server"), feature = "http1"),
all(feature = "server", feature = "http2")
))]
Service, /// User tried to send a certain header in an unexpected context. /// /// For example, sending both `content-length` and `transfer-encoding`. #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")]
UnexpectedHeader, /// User tried to respond with a 1xx (not 101) response code. #[cfg(feature = "http1")] #[cfg(feature = "server")]
UnsupportedStatusCode,
/// User tried polling for an upgrade that doesn't exist.
NoUpgrade,
/// User polled for an upgrade, but low-level API is not using upgrades. #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
ManualUpgrade,
/// The dispatch task is gone. #[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
DispatchGone,
/// User aborted in an FFI callback. #[cfg(feature = "ffi")]
AbortedByCallback,
}
// Sentinel type to indicate the error was caused by a timeout. #[derive(Debug)] pub(super) struct TimedOut;
impl Error { /// Returns true if this was an HTTP parse error. pubfn is_parse(&self) -> bool {
matches!(self.inner.kind, Kind::Parse(_))
}
/// Returns true if this was an HTTP parse error caused by a message that was too large. #[cfg(all(feature = "http1", feature = "server"))] pubfn is_parse_too_large(&self) -> bool {
matches!( self.inner.kind,
Kind::Parse(Parse::TooLarge) | Kind::Parse(Parse::UriTooLong)
)
}
/// Returns true if this was an HTTP parse error caused by an invalid response status code or /// reason phrase. pubfn is_parse_status(&self) -> bool {
matches!(self.inner.kind, Kind::Parse(Parse::Status))
}
/// Returns true if this was an HTTP parse error caused by HTTP2 preface sent over an HTTP1 /// connection. #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] pubfn is_parse_version_h2(&self) -> bool {
matches!(self.inner.kind, Kind::Parse(Parse::VersionH2))
}
/// Returns true if this error was caused by user code. pubfn is_user(&self) -> bool {
matches!(self.inner.kind, Kind::User(_))
}
/// Returns true if this was about a `Request` that was canceled. pubfn is_canceled(&self) -> bool {
matches!(self.inner.kind, Kind::Canceled)
}
/// 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`]. /// /// [`half_close`]: crate::server::conn::http1::Builder::half_close() pubfn is_incomplete_message(&self) -> bool { #[cfg(not(all(any(feature = "client", feature = "server"), feature = "http1")))] returnfalse;
/// Returns true if the error was caused while calling `AsyncWrite::shutdown()`. pubfn is_shutdown(&self) -> bool { #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] if matches!(self.inner.kind, Kind::Shutdown) { returntrue;
} false
}
/// Returns true if the error was caused by a timeout. pubfn is_timeout(&self) -> bool { #[cfg(all(feature = "http1", feature = "server"))] if matches!(self.inner.kind, Kind::HeaderTimeout) { returntrue;
} self.find_source::<TimedOut>().is_some()
}
#[cfg(feature = "http2")] #[test] fn h2_reason_nested() { let recvd = Error::new_h2(h2::Error::from(h2::Reason::HTTP_1_1_REQUIRED)); // Suppose a user were proxying the received error let svc_err = Error::new_user_service(recvd);
assert_eq!(svc_err.h2_reason(), h2::Reason::HTTP_1_1_REQUIRED);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.