From 9bcbadd81a6b47ce695ff6bddeb0c6001cd8a735 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 23 Dec 2022 12:17:14 -0800 Subject: [PATCH] improve some errors --- web3_proxy/src/bin/web3_proxy_cli/check_config.rs | 5 +---- web3_proxy/src/frontend/authorization.rs | 11 +++++++---- web3_proxy/src/frontend/rpc_proxy_ws.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/web3_proxy/src/bin/web3_proxy_cli/check_config.rs b/web3_proxy/src/bin/web3_proxy_cli/check_config.rs index 90ddf178..521363ca 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/check_config.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/check_config.rs @@ -85,10 +85,7 @@ impl CheckConfigSubCommand { if num_errors == 0 { Ok(()) } else { - Err(anyhow::anyhow!(format!( - "there were {} errors!", - num_errors - ))) + Err(anyhow::anyhow!("there were {} errors!", num_errors)) } } } diff --git a/web3_proxy/src/frontend/authorization.rs b/web3_proxy/src/frontend/authorization.rs index e3efb332..c102c5e9 100644 --- a/web3_proxy/src/frontend/authorization.rs +++ b/web3_proxy/src/frontend/authorization.rs @@ -243,7 +243,7 @@ impl Authorization { None => {} Some(allowed_ips) => { if !allowed_ips.iter().any(|x| x.contains(&ip)) { - return Err(anyhow::anyhow!("IP is not allowed!")); + return Err(anyhow::anyhow!("IP ({}) is not allowed!", ip)); } } } @@ -255,7 +255,7 @@ impl Authorization { (None, Some(_)) => return Err(anyhow::anyhow!("Origin required")), (Some(origin), Some(allowed_origins)) => { if !allowed_origins.contains(origin) { - return Err(anyhow::anyhow!("IP is not allowed!")); + return Err(anyhow::anyhow!("Origin ({}) is not allowed!", origin)); } } } @@ -267,7 +267,7 @@ impl Authorization { (None, Some(_)) => return Err(anyhow::anyhow!("Referer required")), (Some(referer), Some(allowed_referers)) => { if !allowed_referers.contains(referer) { - return Err(anyhow::anyhow!("Referer is not allowed!")); + return Err(anyhow::anyhow!("Referer ({:?}) is not allowed!", referer)); } } } @@ -279,7 +279,10 @@ impl Authorization { (None, Some(_)) => return Err(anyhow::anyhow!("User agent required")), (Some(user_agent), Some(allowed_user_agents)) => { if !allowed_user_agents.contains(user_agent) { - return Err(anyhow::anyhow!("User agent is not allowed!")); + return Err(anyhow::anyhow!( + "User agent ({}) is not allowed!", + user_agent + )); } } } diff --git a/web3_proxy/src/frontend/rpc_proxy_ws.rs b/web3_proxy/src/frontend/rpc_proxy_ws.rs index 6a189d94..fedc222a 100644 --- a/web3_proxy/src/frontend/rpc_proxy_ws.rs +++ b/web3_proxy/src/frontend/rpc_proxy_ws.rs @@ -253,7 +253,7 @@ async fn handle_socket_payload( FrontendErrorResponse::Anyhow(err) => Err(err), _ => { error!("handle this better! {:?}", err); - Err(anyhow::anyhow!(format!("unexpected error! {:?}", err))) + Err(anyhow::anyhow!("unexpected error! {:?}", err)) } }, |(response, _)| Ok(response),