From e0f700189bc5765f6d4aaf93cfc8ca4a8692f148 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 17 Aug 2023 13:44:12 -0700 Subject: [PATCH] fix error code on method not implemented and error_response user_response bools --- Cargo.lock | 4 ++-- web3_proxy/Cargo.toml | 2 +- web3_proxy/src/app/mod.rs | 25 +++++++++++++++-------- web3_proxy/src/app/ws.rs | 2 +- web3_proxy/src/errors.rs | 21 +++++++++---------- web3_proxy/src/frontend/users/rpc_keys.rs | 4 +++- web3_proxy_cli/Cargo.toml | 2 +- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef181c7f..7fe350d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index cb476907..9a6a87c9 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -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 diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 142f94da..6a83f40c 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -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" diff --git a/web3_proxy/src/app/ws.rs b/web3_proxy/src/app/ws.rs index 3656d03c..16b980e9 100644 --- a/web3_proxy/src/app/ws.rs +++ b/web3_proxy/src/app/ws.rs @@ -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(), )); } diff --git a/web3_proxy/src/errors.rs b/web3_proxy/src/errors.rs index 7f62d2b3..f11321ec 100644 --- a/web3_proxy/src/errors.rs +++ b/web3_proxy/src/errors.rs @@ -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", + })), }, ) } diff --git a/web3_proxy/src/frontend/users/rpc_keys.rs b/web3_proxy/src/frontend/users/rpc_keys.rs index dce4fc22..7fa2959a 100644 --- a/web3_proxy/src/frontend/users/rpc_keys.rs +++ b/web3_proxy/src/frontend/users/rpc_keys.rs @@ -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. diff --git a/web3_proxy_cli/Cargo.toml b/web3_proxy_cli/Cargo.toml index 40ca0a78..a9c71f63 100644 --- a/web3_proxy_cli/Cargo.toml +++ b/web3_proxy_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "web3_proxy_cli" -version = "1.42.8" +version = "1.42.9" edition = "2021" default-run = "web3_proxy_cli"