fix method not found jsonrpc error codes

This commit is contained in:
Bryan Stitt 2023-08-17 15:32:22 -07:00
parent 6be05bab4b
commit 10a8620044
4 changed files with 19 additions and 21 deletions

View File

@ -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()));

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::MethodNotImplemented(
return Err(Web3ProxyError::MethodNotFound(
subscribe_to.to_owned().into(),
));
}

View File

@ -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());

View File

@ -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.