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`.
This commit is contained in:
		
							
								
								
									
										18
									
								
								src/error.rs
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								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<httparse::Error> for Error { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<Http2Error> 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(..)); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user