Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Fix faucet errors when server returns a 503 #18553

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{
};

use anyhow::{anyhow, bail, ensure, Context};
use axum::http::StatusCode;
use bip32::DerivationPath;
use clap::*;
use colored::Colorize;
Expand Down Expand Up @@ -2524,15 +2525,26 @@ pub async fn request_tokens_from_faucet(
.json(&json_body)
.send()
.await?;
if resp.status() == 429 {
bail!("Faucet received too many requests from this IP address. Please try again after 60 minutes.");
}
let faucet_resp: FaucetResponse = resp.json().await?;

if let Some(err) = faucet_resp.error {
bail!("Faucet request was unsuccessful: {err}")
} else {
println!("Request successful. It can take up to 1 minute to get the coin. Run sui client gas to check your gas coins.");
match resp.status() {
StatusCode::ACCEPTED => {
let faucet_resp: FaucetResponse = resp.json().await?;

if let Some(err) = faucet_resp.error {
bail!("Faucet request was unsuccessful: {err}")
} else {
println!("Request successful. It can take up to 1 minute to get the coin. Run sui client gas to check your gas coins.");
}
}
StatusCode::TOO_MANY_REQUESTS => {
bail!("Faucet service received too many requests from this IP address. Please try again after 60 minutes.");
}
StatusCode::SERVICE_UNAVAILABLE => {
bail!("Faucet service is currently overloaded or unavailable. Please try again later.");
}
status_code => {
bail!("Faucet request was unsuccessful: {status_code}");
}
}
Ok(())
}
Expand Down
Loading