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 {
fn description(&self) -> &str {
match *self {
Client(_) => "an unknown error occured",
Io(_) => "an I/O error occured",
JsonSerialization(_) => "a JSON serialization error occured",
Client(err) => err,
Io(ref err) => err.description(),
JsonSerialization(ref err) => err.description(),
}
}
fn cause(&self) -> Option<&StdError> {
match *self {
Io(ref err) => Some(&*err as &StdError),
JsonSerialization(ref err) => Some(&*err as &StdError),
_ => None,
}
}

View File

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

View File

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

View File

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