aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-04 17:45:08 -0700
committerBryan Newbold <bnewbold@robocracy.org>2022-11-04 17:45:08 -0700
commite6a180e9eed4273db24a59f8e06afa117cfe39a9 (patch)
treeec5fdd219f0c249d79780e3ea59bd40769b6f408
parent6c5c1e84b3540e3a4da81334f34b4e53cc818f4d (diff)
downloadadenosine-e6a180e9eed4273db24a59f8e06afa117cfe39a9.tar.gz
adenosine-e6a180e9eed4273db24a59f8e06afa117cfe39a9.zip
cli: slightly better error handling
-rw-r--r--adenosine-cli/src/lib.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/adenosine-cli/src/lib.rs b/adenosine-cli/src/lib.rs
index 8ffeb88..a3f1dac 100644
--- a/adenosine-cli/src/lib.rs
+++ b/adenosine-cli/src/lib.rs
@@ -67,10 +67,17 @@ impl XrpcClient {
.get(format!("{}/xrpc/{}", self.host, nsid))
.query(&params)
.send()?;
+ // TODO: refactor this error handling stuff into single method
if res.status() == 400 {
let val: Value = res.json()?;
return Err(anyhow!(
- "XRPC Bad Request: {}",
+ "XRPC Bad Request (400): {}",
+ val["message"].as_str().unwrap_or("unknown")
+ ));
+ } else if res.status() == 500 {
+ let val: Value = res.json()?;
+ return Err(anyhow!(
+ "XRPC Internal Error (500): {}",
val["message"].as_str().unwrap_or("unknown")
));
}
@@ -93,7 +100,13 @@ impl XrpcClient {
if res.status() == 400 {
let val: Value = res.json()?;
return Err(anyhow!(
- "XRPC Bad Request: {}",
+ "XRPC Bad Request (400): {}",
+ val["message"].as_str().unwrap_or("unknown")
+ ));
+ } else if res.status() == 500 {
+ let val: Value = res.json()?;
+ return Err(anyhow!(
+ "XRPC Internal Error (500): {}",
val["message"].as_str().unwrap_or("unknown")
));
}
@@ -121,7 +134,13 @@ impl XrpcClient {
if res.status() == 400 {
let val: Value = res.json()?;
return Err(anyhow!(
- "XRPC Bad Request: {}",
+ "XRPC Bad Request (400): {}",
+ val["message"].as_str().unwrap_or("unknown")
+ ));
+ } else if res.status() == 500 {
+ let val: Value = res.json()?;
+ return Err(anyhow!(
+ "XRPC Internal Error (500): {}",
val["message"].as_str().unwrap_or("unknown")
));
}