Skip to content

Commit

Permalink
Update fund error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Jul 30, 2024
1 parent 4a7349f commit 103d1c2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/soroban-cli/src/config/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub enum Error {
FailedToParseJSON(String, serde_json::Error),
#[error("Invalid URL {0}")]
InvalidUrl(String),
#[error("Inproper response {0}")]
InproperResponse(String),
#[error("funding failed: {0}")]
FundingFailed(String),
}

#[derive(Debug, clap::Args, Clone, Default)]
Expand Down Expand Up @@ -149,16 +149,16 @@ impl Network {
return Err(Error::InvalidUrl(uri.to_string()));
}
};
let request_successful = response.status().is_success();
let body = hyper::body::to_bytes(response.into_body()).await?;
let res = serde_json::from_slice::<serde_json::Value>(&body)
.map_err(|e| Error::FailedToParseJSON(uri.to_string(), e))?;
tracing::debug!("{res:#?}");
if let Some(detail) = res.get("detail").and_then(Value::as_str) {
if detail.contains("createAccountAlreadyExist") {
eprintln!("Account already exists");
if !request_successful {
if let Some(detail) = res.get("detail").and_then(Value::as_str) {
return Err(Error::FundingFailed(detail.to_string()));
}
} else if res.get("successful").is_none() {
return Err(Error::InproperResponse(res.to_string()));
return Err(Error::FundingFailed("unknown cause".to_string()));
}
Ok(())
}
Expand Down

0 comments on commit 103d1c2

Please sign in to comment.