less json errors
This commit is contained in:
parent
d2033b0a4e
commit
24b76a33bc
@ -469,9 +469,11 @@ impl Web3Connections {
|
|||||||
.request(&request.method, &request.params)
|
.request(&request.method, &request.params)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let response =
|
match JsonRpcForwardedResponse::from_response_result(
|
||||||
JsonRpcForwardedResponse::from_response_result(response_result, request.id);
|
response_result,
|
||||||
|
request.id.clone(),
|
||||||
|
) {
|
||||||
|
Ok(response) => {
|
||||||
if response.error.is_some() {
|
if response.error.is_some() {
|
||||||
trace!(?response, "Sending error reply",);
|
trace!(?response, "Sending error reply",);
|
||||||
// errors already sent false to the in_flight_tx
|
// errors already sent false to the in_flight_tx
|
||||||
@ -481,6 +483,19 @@ impl Web3Connections {
|
|||||||
|
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!(?self, ?e, "Backend server error!");
|
||||||
|
|
||||||
|
// TODO: sleep how long? until synced_connections changes or rate limits are available
|
||||||
|
sleep(Duration::from_millis(100)).await;
|
||||||
|
|
||||||
|
// TODO: when we retry, depending on the error, skip using this same server
|
||||||
|
// for example, if rpc isn't available on this server, retrying is bad
|
||||||
|
// but if an http error, retrying on same is probably fine
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(None) => {
|
Err(None) => {
|
||||||
warn!(?self, "No servers in sync!");
|
warn!(?self, "No servers in sync!");
|
||||||
|
|
||||||
|
@ -184,9 +184,9 @@ impl JsonRpcForwardedResponse {
|
|||||||
pub fn from_response_result(
|
pub fn from_response_result(
|
||||||
result: Result<Box<RawValue>, ProviderError>,
|
result: Result<Box<RawValue>, ProviderError>,
|
||||||
id: Box<RawValue>,
|
id: Box<RawValue>,
|
||||||
) -> Self {
|
) -> anyhow::Result<Self> {
|
||||||
match result {
|
match result {
|
||||||
Ok(response) => Self::from_response(response, id),
|
Ok(response) => Ok(Self::from_response(response, id)),
|
||||||
Err(e) => Self::from_ethers_error(e, id),
|
Err(e) => Self::from_ethers_error(e, id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ impl JsonRpcForwardedResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_ethers_error(e: ProviderError, id: Box<RawValue>) -> Self {
|
pub fn from_ethers_error(e: ProviderError, id: Box<RawValue>) -> anyhow::Result<Self> {
|
||||||
// TODO: move turning ClientError into json to a helper function?
|
// TODO: move turning ClientError into json to a helper function?
|
||||||
let code;
|
let code;
|
||||||
let message: String;
|
let message: String;
|
||||||
@ -216,47 +216,46 @@ impl JsonRpcForwardedResponse {
|
|||||||
|
|
||||||
match e {
|
match e {
|
||||||
ProviderError::JsonRpcClientError(e) => {
|
ProviderError::JsonRpcClientError(e) => {
|
||||||
// TODO: we should check what type the provider is rather than trying to downcast both types of errors
|
// TODO: check what type the provider is rather than trying to downcast both types of errors
|
||||||
if let Some(e) = e.downcast_ref::<HttpClientError>() {
|
let e = e.downcast::<HttpClientError>();
|
||||||
match &*e {
|
|
||||||
|
if let Ok(e) = e {
|
||||||
|
match *e {
|
||||||
HttpClientError::JsonRpcError(e) => {
|
HttpClientError::JsonRpcError(e) => {
|
||||||
code = e.code;
|
code = e.code;
|
||||||
message = e.message.clone();
|
message = e.message.clone();
|
||||||
data = e.data.clone();
|
data = e.data;
|
||||||
}
|
}
|
||||||
e => {
|
e => {
|
||||||
// TODO: improve this
|
// this is not an rpc error. keep it as an error
|
||||||
code = -32603;
|
return Err(e.into());
|
||||||
message = format!("{}", e);
|
|
||||||
data = None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(e) = e.downcast_ref::<WsClientError>() {
|
} else {
|
||||||
match &*e {
|
// it wasn't an HttpClientError. try WsClientError
|
||||||
|
let e = e.unwrap_err().downcast::<WsClientError>();
|
||||||
|
|
||||||
|
if let Ok(e) = e {
|
||||||
|
match *e {
|
||||||
WsClientError::JsonRpcError(e) => {
|
WsClientError::JsonRpcError(e) => {
|
||||||
code = e.code;
|
code = e.code;
|
||||||
message = e.message.clone();
|
message = e.message.clone();
|
||||||
data = e.data.clone();
|
data = e.data;
|
||||||
}
|
}
|
||||||
e => {
|
e => {
|
||||||
// TODO: improve this
|
// this is not an rpc error. keep it as an error
|
||||||
code = -32603;
|
return Err(e.into());
|
||||||
message = format!("{}", e);
|
|
||||||
data = None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
code = -32603;
|
|
||||||
message = format!("{}", e);
|
|
||||||
data = None;
|
|
||||||
}
|
}
|
||||||
|
e => return Err(e.into()),
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Ok(Self {
|
||||||
jsonrpc: "2.0".to_string(),
|
jsonrpc: "2.0".to_string(),
|
||||||
id,
|
id,
|
||||||
result: None,
|
result: None,
|
||||||
@ -265,7 +264,7 @@ impl JsonRpcForwardedResponse {
|
|||||||
message,
|
message,
|
||||||
data,
|
data,
|
||||||
}),
|
}),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user