From 48e9ca2f70f6c6475f1579ae9212af7b4ca87e88 Mon Sep 17 00:00:00 2001 From: Marko Lalic Date: Thu, 28 May 2015 16:16:55 +0200 Subject: [PATCH] feat(http2): add new error variant for HTTP/2 Automatic conversion from the `solicit::http::HttpError` is also provided. BREAKING CHANGE: A new variant `Http2` added to a public enum `hyper::Error`. --- src/error.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 59cc273b23..299d2c02b5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,6 +6,7 @@ use std::io::Error as IoError; use httparse; use openssl::ssl::error::SslError; use url; +use solicit::http::HttpError as Http2Error; use self::Error::{ Method, @@ -15,7 +16,8 @@ use self::Error::{ Status, Io, Ssl, - TooLarge + TooLarge, + Http2, }; @@ -40,7 +42,9 @@ pub enum Error { /// An `io::Error` that occurred while trying to read or write to a network stream. Io(IoError), /// An error from the `openssl` library. - Ssl(SslError) + Ssl(SslError), + /// An HTTP/2-specific error, coming from the `solicit` library. + Http2(Http2Error), } impl fmt::Display for Error { @@ -60,6 +64,7 @@ impl StdError for Error { Uri(ref e) => e.description(), Io(ref e) => e.description(), Ssl(ref e) => e.description(), + Http2(ref e) => e.description(), } } @@ -68,6 +73,7 @@ impl StdError for Error { Io(ref error) => Some(error), Ssl(ref error) => Some(error), Uri(ref error) => Some(error), + Http2(ref error) => Some(error), _ => None, } } @@ -108,12 +114,19 @@ impl From for Error { } } +impl From for Error { + fn from(err: Http2Error) -> Error { + Error::Http2(err) + } +} + #[cfg(test)] mod tests { use std::error::Error as StdError; use std::io; use httparse; use openssl::ssl::error::SslError; + use solicit::http::HttpError as Http2Error; use url; use super::Error; use super::Error::*; @@ -156,6 +169,7 @@ mod tests { from_and_cause!(io::Error::new(io::ErrorKind::Other, "other") => Io(..)); from_and_cause!(url::ParseError::EmptyHost => Uri(..)); from_and_cause!(SslError::SslSessionClosed => Ssl(..)); + from_and_cause!(Http2Error::UnknownStreamId => Http2(..)); from!(SslError::StreamError(io::Error::new(io::ErrorKind::Other, "ssl negotiation")) => Io(..));