diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-04 17:45:08 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-04 17:45:08 -0700 |
commit | e6a180e9eed4273db24a59f8e06afa117cfe39a9 (patch) | |
tree | ec5fdd219f0c249d79780e3ea59bd40769b6f408 | |
parent | 6c5c1e84b3540e3a4da81334f34b4e53cc818f4d (diff) | |
download | adenosine-e6a180e9eed4273db24a59f8e06afa117cfe39a9.tar.gz adenosine-e6a180e9eed4273db24a59f8e06afa117cfe39a9.zip |
cli: slightly better error handling
-rw-r--r-- | adenosine-cli/src/lib.rs | 25 |
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(¶ms) .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") )); } |