fix error code on method not implemented and error_response user_response bools

This commit is contained in:
Bryan Stitt 2023-08-17 13:44:12 -07:00
parent 36eb520f84
commit e0f700189b
7 changed files with 34 additions and 26 deletions

4
Cargo.lock generated
View File

@ -7242,7 +7242,7 @@ dependencies = [
[[package]]
name = "web3_proxy"
version = "1.42.8"
version = "1.42.9"
dependencies = [
"anyhow",
"arc-swap",
@ -7323,7 +7323,7 @@ dependencies = [
[[package]]
name = "web3_proxy_cli"
version = "1.42.8"
version = "1.42.9"
dependencies = [
"env_logger",
"parking_lot",

View File

@ -1,6 +1,6 @@
[package]
name = "web3_proxy"
version = "1.42.8"
version = "1.42.9"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1169,6 +1169,9 @@ impl Web3ProxyApp {
request_metadata
.error_response
.store(false, Ordering::Release);
request_metadata
.user_error_response
.store(false, Ordering::Release);
(StatusCode::OK, response_data)
}
@ -1176,12 +1179,18 @@ impl Web3ProxyApp {
request_metadata
.error_response
.store(false, Ordering::Release);
request_metadata
.user_error_response
.store(false, Ordering::Release);
err.as_response_parts()
}
Err(Web3ProxyError::JsonRpcResponse(response_data)) => {
request_metadata
.error_response
.store(false, Ordering::Release);
request_metadata
.user_error_response
.store(response_data.is_error(), Ordering::Release);
(StatusCode::OK, response_data)
@ -1198,6 +1207,9 @@ impl Web3ProxyApp {
request_metadata
.error_response
.store(true, Ordering::Release);
request_metadata
.user_error_response
.store(false, Ordering::Release);
err.as_response_parts()
}
@ -1302,12 +1314,10 @@ impl Web3ProxyApp {
| "shh_post"
| "shh_uninstallFilter"
| "shh_version") => {
// i don't think we will ever support these methods. maybe do Forbidden?
// TODO: what error code?
JsonRpcErrorData::from(format!(
return Err(Web3ProxyError::MethodNotImplemented(format!(
"the method {} does not exist/is not available",
method
)).into()
).into()));
}
// TODO: implement these commands
method @ ("eth_getFilterChanges"
@ -1317,13 +1327,10 @@ impl Web3ProxyApp {
| "eth_newPendingTransactionFilter"
| "eth_pollSubscriptions"
| "eth_uninstallFilter") => {
// TODO: unsupported command stat. use the count to prioritize new features
// TODO: what error code?
JsonRpcErrorData::from(format!(
return Err(Web3ProxyError::MethodNotImplemented(format!(
"the method {} is not yet implemented. contact us if you need this",
method
))
.into()
).into()));
}
method @ ("eth_sendUserOperation"
| "eth_estimateUserOperationGas"

View File

@ -125,7 +125,7 @@ impl Web3ProxyApp {
});
} else {
// TODO: make sure this gets a CU cost of unimplemented instead of the normal eth_subscribe cost?
return Err(Web3ProxyError::NotImplemented(
return Err(Web3ProxyError::MethodNotImplemented(
subscribe_to.to_owned().into(),
));
}

View File

@ -121,7 +121,7 @@ pub enum Web3ProxyError {
NotFound,
#[error(ignore)]
#[from(ignore)]
NotImplemented(Cow<'static, str>),
MethodNotImplemented(Cow<'static, str>),
NoVolatileRedisDatabase,
/// make it easy to skip caching large results
#[error(ignore)]
@ -751,18 +751,17 @@ impl Web3ProxyError {
},
)
}
Self::NotImplemented(msg) => {
warn!("NotImplemented: {}", msg);
Self::MethodNotImplemented(method) => {
warn!("NotImplemented: {}", method);
(
StatusCode::NOT_IMPLEMENTED,
StatusCode::OK,
JsonRpcErrorData {
message: format!(
"{} is not yet implemented. contact us if you need this",
msg
)
.into(),
code: StatusCode::NOT_IMPLEMENTED.as_u16().into(),
data: None,
message: "Method not found".into(),
code: -32601,
data: Some(json!({
"method": method,
"extra": "contact us if you need this",
})),
},
)
}

View File

@ -129,7 +129,9 @@ pub async fn rpc_keys_delete(
let _user = app.bearer_is_authorized(bearer).await?;
// TODO: think about how cascading deletes and billing should work
Err(Web3ProxyError::NotImplemented("rpc_keys_delete".into()))
Err(Web3ProxyError::MethodNotImplemented(
"rpc_keys_delete".into(),
))
}
/// the JSON input to the `rpc_keys_management` handler.

View File

@ -1,6 +1,6 @@
[package]
name = "web3_proxy_cli"
version = "1.42.8"
version = "1.42.9"
edition = "2021"
default-run = "web3_proxy_cli"