committed by
Michael Vines
parent
0ec301f1c3
commit
88177d33fd
@ -125,46 +125,42 @@ impl RpcSender for HttpSender {
|
|||||||
.body(request_json)
|
.body(request_json)
|
||||||
.send()
|
.send()
|
||||||
})
|
})
|
||||||
};
|
}?;
|
||||||
|
|
||||||
match response {
|
if !response.status().is_success() {
|
||||||
Ok(response) => {
|
if response.status() == StatusCode::TOO_MANY_REQUESTS
|
||||||
if !response.status().is_success() {
|
&& too_many_requests_retries > 0
|
||||||
if response.status() == StatusCode::TOO_MANY_REQUESTS
|
{
|
||||||
&& too_many_requests_retries > 0
|
let mut duration = Duration::from_millis(500);
|
||||||
{
|
if let Some(retry_after) = response.headers().get(RETRY_AFTER) {
|
||||||
let mut duration = Duration::from_millis(500);
|
if let Ok(retry_after) = retry_after.to_str() {
|
||||||
if let Some(retry_after) = response.headers().get(RETRY_AFTER) {
|
if let Ok(retry_after) = retry_after.parse::<u64>() {
|
||||||
if let Ok(retry_after) = retry_after.to_str() {
|
if retry_after < 120 {
|
||||||
if let Ok(retry_after) = retry_after.parse::<u64>() {
|
duration = Duration::from_secs(retry_after);
|
||||||
if retry_after < 120 {
|
|
||||||
duration = Duration::from_secs(retry_after);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
too_many_requests_retries -= 1;
|
too_many_requests_retries -= 1;
|
||||||
debug!(
|
debug!(
|
||||||
"Too many requests: server responded with {:?}, {} retries left, pausing for {:?}",
|
"Too many requests: server responded with {:?}, {} retries left, pausing for {:?}",
|
||||||
response, too_many_requests_retries, duration
|
response, too_many_requests_retries, duration
|
||||||
);
|
);
|
||||||
|
|
||||||
sleep(duration);
|
sleep(duration);
|
||||||
stats_updater.add_rate_limited_time(duration);
|
stats_updater.add_rate_limited_time(duration);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(response.error_for_status().unwrap_err().into());
|
return Err(response.error_for_status().unwrap_err().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let response_text = tokio::task::block_in_place(move || response.text())?;
|
let mut json =
|
||||||
|
tokio::task::block_in_place(move || response.json::<serde_json::Value>())?;
|
||||||
let json: serde_json::Value = serde_json::from_str(&response_text)?;
|
if json["error"].is_object() {
|
||||||
if json["error"].is_object() {
|
return match serde_json::from_value::<RpcErrorObject>(json["error"].clone()) {
|
||||||
return match serde_json::from_value::<RpcErrorObject>(json["error"].clone())
|
Ok(rpc_error_object) => {
|
||||||
{
|
let data = match rpc_error_object.code {
|
||||||
Ok(rpc_error_object) => {
|
|
||||||
let data = match rpc_error_object.code {
|
|
||||||
rpc_custom_error::JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE => {
|
rpc_custom_error::JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE => {
|
||||||
match serde_json::from_value::<RpcSimulateTransactionResult>(json["error"]["data"].clone()) {
|
match serde_json::from_value::<RpcSimulateTransactionResult>(json["error"]["data"].clone()) {
|
||||||
Ok(data) => RpcResponseErrorData::SendTransactionPreflightFailure(data),
|
Ok(data) => RpcResponseErrorData::SendTransactionPreflightFailure(data),
|
||||||
@ -185,27 +181,22 @@ impl RpcSender for HttpSender {
|
|||||||
_ => RpcResponseErrorData::Empty
|
_ => RpcResponseErrorData::Empty
|
||||||
};
|
};
|
||||||
|
|
||||||
Err(RpcError::RpcResponseError {
|
Err(RpcError::RpcResponseError {
|
||||||
code: rpc_error_object.code,
|
code: rpc_error_object.code,
|
||||||
message: rpc_error_object.message,
|
message: rpc_error_object.message,
|
||||||
data,
|
data,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
|
||||||
Err(err) => Err(RpcError::RpcRequestError(format!(
|
|
||||||
"Failed to deserialize RPC error response: {} [{}]",
|
|
||||||
serde_json::to_string(&json["error"]).unwrap(),
|
|
||||||
err
|
|
||||||
))
|
|
||||||
.into()),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return Ok(json["result"].clone());
|
Err(err) => Err(RpcError::RpcRequestError(format!(
|
||||||
}
|
"Failed to deserialize RPC error response: {} [{}]",
|
||||||
Err(err) => {
|
serde_json::to_string(&json["error"]).unwrap(),
|
||||||
return Err(err.into());
|
err
|
||||||
}
|
))
|
||||||
|
.into()),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return Ok(json["result"].take());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user