From 10a86200444805635db78c4281c5e9c2a9dafa65 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 17 Aug 2023 15:32:22 -0700 Subject: [PATCH] fix method not found jsonrpc error codes --- web3_proxy/src/app/mod.rs | 4 +-- web3_proxy/src/app/ws.rs | 2 +- web3_proxy/src/errors.rs | 30 +++++++++++------------ web3_proxy/src/frontend/users/rpc_keys.rs | 4 +-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 6a83f40c..a2cfb447 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1314,7 +1314,7 @@ impl Web3ProxyApp { | "shh_post" | "shh_uninstallFilter" | "shh_version") => { - return Err(Web3ProxyError::MethodNotImplemented(format!( + return Err(Web3ProxyError::MethodNotFound(format!( "the method {} does not exist/is not available", method ).into())); @@ -1327,7 +1327,7 @@ impl Web3ProxyApp { | "eth_newPendingTransactionFilter" | "eth_pollSubscriptions" | "eth_uninstallFilter") => { - return Err(Web3ProxyError::MethodNotImplemented(format!( + return Err(Web3ProxyError::MethodNotFound(format!( "the method {} is not yet implemented. contact us if you need this", method ).into())); diff --git a/web3_proxy/src/app/ws.rs b/web3_proxy/src/app/ws.rs index 16b980e9..5ecc2d9b 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::MethodNotImplemented( + return Err(Web3ProxyError::MethodNotFound( subscribe_to.to_owned().into(), )); } diff --git a/web3_proxy/src/errors.rs b/web3_proxy/src/errors.rs index f11321ec..10d7c6a4 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)] - MethodNotImplemented(Cow<'static, str>), + MethodNotFound(Cow<'static, str>), NoVolatileRedisDatabase, /// make it easy to skip caching large results #[error(ignore)] @@ -618,6 +618,20 @@ impl Web3ProxyError { // TODO: do this without clone? the Arc needed it though (StatusCode::OK, jsonrpc_error_data.clone()) } + Self::MethodNotFound(method) => { + warn!("MethodNotFound: {}", method); + ( + StatusCode::OK, + JsonRpcErrorData { + message: "Method not found".into(), + code: -32601, + data: Some(json!({ + "method": method, + "extra": "contact us if you need this", + })), + }, + ) + } Self::MsgPackEncode(err) => { warn!(?err, "MsgPackEncode"); ( @@ -751,20 +765,6 @@ impl Web3ProxyError { }, ) } - Self::MethodNotImplemented(method) => { - warn!("NotImplemented: {}", method); - ( - StatusCode::OK, - JsonRpcErrorData { - message: "Method not found".into(), - code: -32601, - data: Some(json!({ - "method": method, - "extra": "contact us if you need this", - })), - }, - ) - } Self::JsonRpcResponse(response_enum) => { // TODO: shame we have to clone, but its an Arc so its not terrible return (StatusCode::OK, response_enum.clone()); diff --git a/web3_proxy/src/frontend/users/rpc_keys.rs b/web3_proxy/src/frontend/users/rpc_keys.rs index 7fa2959a..6232883e 100644 --- a/web3_proxy/src/frontend/users/rpc_keys.rs +++ b/web3_proxy/src/frontend/users/rpc_keys.rs @@ -129,9 +129,7 @@ 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::MethodNotImplemented( - "rpc_keys_delete".into(), - )) + Err(Web3ProxyError::MethodNotFound("rpc_keys_delete".into())) } /// the JSON input to the `rpc_keys_management` handler.