From 4c157cfcf73639075056c93680ea0faab2477afb Mon Sep 17 00:00:00 2001 From: yenicelik Date: Sun, 25 Jun 2023 15:05:27 -0400 Subject: [PATCH] made paymentrequired error code instead of introducing a new one --- web3_proxy/src/errors.rs | 12 ------------ web3_proxy/src/stats/influxdb_queries.rs | 10 +++++----- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/web3_proxy/src/errors.rs b/web3_proxy/src/errors.rs index 0db91821..e0241502 100644 --- a/web3_proxy/src/errors.rs +++ b/web3_proxy/src/errors.rs @@ -44,7 +44,6 @@ impl From for Web3ProxyResult<()> { pub enum Web3ProxyError { Abi(ethers::abi::Error), AccessDenied, - AccessDeniedLowBalance, AccessDeniedNoSubuser, #[error(ignore)] Anyhow(anyhow::Error), @@ -190,17 +189,6 @@ impl Web3ProxyError { }, ) } - Self::AccessDeniedLowBalance => { - trace!("access denied due to low balance"); - ( - StatusCode::FORBIDDEN, - JsonRpcErrorData { - message: "FORBIDDEN: LOW BALANCE".into(), - code: StatusCode::FORBIDDEN.as_u16().into(), - data: None, - }, - ) - } Self::AccessDeniedNoSubuser => { trace!("access denied not a subuser"); ( diff --git a/web3_proxy/src/stats/influxdb_queries.rs b/web3_proxy/src/stats/influxdb_queries.rs index d2380f23..e1f432ee 100644 --- a/web3_proxy/src/stats/influxdb_queries.rs +++ b/web3_proxy/src/stats/influxdb_queries.rs @@ -67,14 +67,14 @@ pub async fn query_user_stats<'a>( if user_balance.total_spent_outside_free_tier - user_balance.total_deposits < Decimal::from(0) { - debug!("User has 0 balance"); - return Err(Web3ProxyError::AccessDeniedLowBalance); + trace!("User has 0 balance"); + return Err(Web3ProxyError::PaymentRequired); } // Otherwise make the user pass } None => { - debug!("User does not have a balance record, implying that he has no balance. Users must have a balance to access their stats dashboards"); - return Err(Web3ProxyError::AccessDeniedLowBalance); + trace!("User does not have a balance record, implying that he has no balance. Users must have a balance to access their stats dashboards"); + return Err(Web3ProxyError::PaymentRequired); } } @@ -99,7 +99,7 @@ pub async fn query_user_stats<'a>( { Some(secondary_user_record) => { if secondary_user_record.role == Role::Collaborator { - debug!("Subuser is only a collaborator, collaborators cannot see stats"); + trace!("Subuser is only a collaborator, collaborators cannot see stats"); return Err(Web3ProxyError::AccessDenied); } }