Skip to content

Commit 48e9ca2

Browse files
committed
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`.
1 parent 3122ffe commit 48e9ca2

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/error.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::Error as IoError;
66
use httparse;
77
use openssl::ssl::error::SslError;
88
use url;
9+
use solicit::http::HttpError as Http2Error;
910

1011
use self::Error::{
1112
Method,
@@ -15,7 +16,8 @@ use self::Error::{
1516
Status,
1617
Io,
1718
Ssl,
18-
TooLarge
19+
TooLarge,
20+
Http2,
1921
};
2022

2123

@@ -40,7 +42,9 @@ pub enum Error {
4042
/// An `io::Error` that occurred while trying to read or write to a network stream.
4143
Io(IoError),
4244
/// An error from the `openssl` library.
43-
Ssl(SslError)
45+
Ssl(SslError),
46+
/// An HTTP/2-specific error, coming from the `solicit` library.
47+
Http2(Http2Error),
4448
}
4549

4650
impl fmt::Display for Error {
@@ -60,6 +64,7 @@ impl StdError for Error {
6064
Uri(ref e) => e.description(),
6165
Io(ref e) => e.description(),
6266
Ssl(ref e) => e.description(),
67+
Http2(ref e) => e.description(),
6368
}
6469
}
6570

@@ -68,6 +73,7 @@ impl StdError for Error {
6873
Io(ref error) => Some(error),
6974
Ssl(ref error) => Some(error),
7075
Uri(ref error) => Some(error),
76+
Http2(ref error) => Some(error),
7177
_ => None,
7278
}
7379
}
@@ -108,12 +114,19 @@ impl From<httparse::Error> for Error {
108114
}
109115
}
110116

117+
impl From<Http2Error> for Error {
118+
fn from(err: Http2Error) -> Error {
119+
Error::Http2(err)
120+
}
121+
}
122+
111123
#[cfg(test)]
112124
mod tests {
113125
use std::error::Error as StdError;
114126
use std::io;
115127
use httparse;
116128
use openssl::ssl::error::SslError;
129+
use solicit::http::HttpError as Http2Error;
117130
use url;
118131
use super::Error;
119132
use super::Error::*;
@@ -156,6 +169,7 @@ mod tests {
156169
from_and_cause!(io::Error::new(io::ErrorKind::Other, "other") => Io(..));
157170
from_and_cause!(url::ParseError::EmptyHost => Uri(..));
158171
from_and_cause!(SslError::SslSessionClosed => Ssl(..));
172+
from_and_cause!(Http2Error::UnknownStreamId => Http2(..));
159173

160174
from!(SslError::StreamError(io::Error::new(io::ErrorKind::Other, "ssl negotiation")) => Io(..));
161175

0 commit comments

Comments
 (0)