Skip to content

Commit

Permalink
feat(http2): add new error variant for HTTP/2
Browse files Browse the repository at this point in the history
Automatic conversion from the `solicit::http::HttpError` is also
provided.

BREAKING CHANGE: A new variant `Http2` added to a public enum
`hyper::Error`.
  • Loading branch information
mlalic committed Jun 2, 2015
1 parent 3122ffe commit 48e9ca2
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,7 +16,8 @@ use self::Error::{
Status,
Io,
Ssl,
TooLarge
TooLarge,
Http2,
};


Expand All @@ -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 {
Expand All @@ -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(),
}
}

Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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(..));

Expand Down

0 comments on commit 48e9ca2

Please sign in to comment.