fix building without tls. close #1
This commit is contained in:
18
src/error.rs
18
src/error.rs
@@ -1,7 +1,11 @@
|
||||
use native_tls::Error as TlsError;
|
||||
use native_tls::HandshakeError;
|
||||
use std::io::Error as IoError;
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
use std::net::TcpStream;
|
||||
#[cfg(feature = "tls")]
|
||||
use native_tls::Error as TlsError;
|
||||
#[cfg(feature = "tls")]
|
||||
use native_tls::HandshakeError;
|
||||
|
||||
/// Errors that are translated to ["synthetic" responses](struct.Response.html#method.synthetic).
|
||||
#[derive(Debug)]
|
||||
@@ -23,8 +27,10 @@ pub enum Error {
|
||||
/// Some unspecified `std::io::Error`. Synthetic error `500`.
|
||||
Io(IoError),
|
||||
/// Some unspecified TLS error. Synthetic error `400`.
|
||||
#[cfg(feature = "tls")]
|
||||
Tls(TlsError),
|
||||
/// Some unspecified TLS handshake error. Synthetic error `500`.
|
||||
#[cfg(feature = "tls")]
|
||||
TlsHandshake(HandshakeError<TcpStream>),
|
||||
}
|
||||
|
||||
@@ -40,7 +46,9 @@ impl Error {
|
||||
Error::BadStatus => 500,
|
||||
Error::BadHeader => 500,
|
||||
Error::Io(_) => 500,
|
||||
#[cfg(feature = "tls")]
|
||||
Error::Tls(_) => 400,
|
||||
#[cfg(feature = "tls")]
|
||||
Error::TlsHandshake(_) => 500,
|
||||
}
|
||||
}
|
||||
@@ -56,7 +64,9 @@ impl Error {
|
||||
Error::BadStatus => "Bad Status",
|
||||
Error::BadHeader => "Bad Header",
|
||||
Error::Io(_) => "Network Error",
|
||||
#[cfg(feature = "tls")]
|
||||
Error::Tls(_) => "TLS Error",
|
||||
#[cfg(feature = "tls")]
|
||||
Error::TlsHandshake(_) => "TLS Handshake Error",
|
||||
}
|
||||
}
|
||||
@@ -72,7 +82,9 @@ impl Error {
|
||||
Error::BadStatus => "Bad Status".to_string(),
|
||||
Error::BadHeader => "Bad Header".to_string(),
|
||||
Error::Io(ioe) => format!("Network Error: {}", ioe),
|
||||
#[cfg(feature = "tls")]
|
||||
Error::Tls(tls) => format!("TLS Error: {}", tls),
|
||||
#[cfg(feature = "tls")]
|
||||
Error::TlsHandshake(he) => format!("TLS Handshake Error: {}", he),
|
||||
}
|
||||
}
|
||||
@@ -84,12 +96,14 @@ impl From<IoError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
impl From<TlsError> for Error {
|
||||
fn from(err: TlsError) -> Error {
|
||||
Error::Tls(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
impl From<HandshakeError<TcpStream>> for Error {
|
||||
fn from(err: HandshakeError<TcpStream>) -> Error {
|
||||
Error::TlsHandshake(err)
|
||||
|
||||
Reference in New Issue
Block a user