Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ciphax committed Feb 19, 2019
1 parent c65e294 commit 5b9a547
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/inwx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum InwxError {
RpcError(RpcError),
ApiError {
method: String,
reason: String,
msg: String
}
}
Expand All @@ -18,7 +19,7 @@ impl fmt::Display for InwxError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&InwxError::RpcError(ref e) => write!(f, "The inwx api call failed: {}", e),
&InwxError::ApiError { ref method, ref msg } => write!(f, "{}: {}", method, msg)
&InwxError::ApiError { ref method, ref msg, ref reason } => write!(f, "method={},msg={},reason={}", method, msg, reason)
}
}
}
Expand All @@ -36,13 +37,25 @@ impl Inwx {
if response.is_success() {
Ok(response)
} else {
let msg = match evaluate_xpath(&response.get_document(), "/methodResponse/params/param/value/struct/member[name/text()=\"msg\"]/value/string/text()") {
let msg = match evaluate_xpath(
&response.get_document(),
"/methodResponse/params/param/value/struct/member[name/text()=\"msg\"]/value/string/text()"
) {
Ok(ref value) => value.string(),
Err(_) => String::new()
};

let reason = match evaluate_xpath(
&response.get_document(),
"/methodResponse/params/param/value/struct/member[name/text()=\"reason\"]/value/string/text()"
) {
Ok(ref value) => value.string(),
Err(_) => String::new()
};

Err(InwxError::ApiError {
msg,
reason,
method
})
}
Expand Down Expand Up @@ -98,7 +111,8 @@ impl Inwx {

Err(InwxError::ApiError {
method: "nameserver.list".to_owned(),
msg: "Domain not found".to_owned()
msg: "Domain not found".to_owned(),
reason: "".to_owned()
})
}

Expand Down Expand Up @@ -156,7 +170,8 @@ impl Inwx {

id.ok_or(InwxError::ApiError {
method: "nameserver.info".to_owned(),
msg: "Record not found".to_owned()
msg: "Record not found".to_owned(),
reason: "".to_owned()
})
}

Expand Down

0 comments on commit 5b9a547

Please sign in to comment.