feat(transport): Improve description of all transport error types

This commit is contained in:
Alexis Mousset
2017-06-17 18:06:47 +02:00
parent 04e9a824b3
commit ff87e4c595
4 changed files with 18 additions and 15 deletions

View File

@@ -27,15 +27,16 @@ impl Display for Error {
impl StdError for Error { impl StdError for Error {
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
Client(_) => "an unknown error occured", Client(err) => err,
Io(_) => "an I/O error occured", Io(ref err) => err.description(),
JsonSerialization(_) => "a JSON serialization error occured", JsonSerialization(ref err) => err.description(),
} }
} }
fn cause(&self) -> Option<&StdError> { fn cause(&self) -> Option<&StdError> {
match *self { match *self {
Io(ref err) => Some(&*err as &StdError), Io(ref err) => Some(&*err as &StdError),
JsonSerialization(ref err) => Some(&*err as &StdError),
_ => None, _ => None,
} }
} }

View File

@@ -25,8 +25,8 @@ impl Display for Error {
impl StdError for Error { impl StdError for Error {
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
Client(_) => "an unknown error occured", Client(err) => err,
Io(_) => "an I/O error occured", Io(ref err) => err.description(),
} }
} }

View File

@@ -46,29 +46,31 @@ impl StdError for Error {
match *self { match *self {
// Try to display the first line of the server's response that usually // Try to display the first line of the server's response that usually
// contains a short humanly readable error message // contains a short humanly readable error message
Transient(ref e) => { Transient(ref err) => {
match e.first_line() { match err.first_line() {
Some(line) => line, Some(line) => line,
None => "undetailed transient error during SMTP transaction", None => "undetailed transient error during SMTP transaction",
} }
} }
Permanent(ref e) => { Permanent(ref err) => {
match e.first_line() { match err.first_line() {
Some(line) => line, Some(line) => line,
None => "undetailed permanent error during SMTP transaction", None => "undetailed permanent error during SMTP transaction",
} }
} }
ResponseParsing(e) => e, ResponseParsing(err) => err,
ChallengeParsing(ref e) => e.description(), ChallengeParsing(ref err) => err.description(),
Utf8Parsing(ref e) => e.description(), Utf8Parsing(ref err) => err.description(),
Resolution => "could not resolve hostname", Resolution => "could not resolve hostname",
Client(e) => e, Client(err) => err,
Io(ref e) => e.description(), Io(ref err) => err.description(),
} }
} }
fn cause(&self) -> Option<&StdError> { fn cause(&self) -> Option<&StdError> {
match *self { match *self {
ChallengeParsing(ref err) => Some(&*err as &StdError),
Utf8Parsing(ref err) => Some(&*err as &StdError),
Io(ref err) => Some(&*err as &StdError), Io(ref err) => Some(&*err as &StdError),
_ => None, _ => None,
} }

View File

@@ -215,7 +215,7 @@ impl SmtpTransportBuilder {
timeout: Some(Duration::new(60, 0)), timeout: Some(Duration::new(60, 0)),
}) })
} }
None => Err(From::from("Could not resolve hostname")), None => Err(Error::Resolution),
} }
} }