call add_response for internal requests

This commit is contained in:
Bryan Stitt 2023-11-14 14:32:39 -08:00
parent c2514fa528
commit c4afad5b49
3 changed files with 23 additions and 4 deletions

@ -2,7 +2,7 @@ use super::{JsonRpcParams, LooseId, SingleRequest};
use crate::{
app::App,
block_number::CacheMode,
errors::Web3ProxyResult,
errors::{Web3ProxyError, Web3ProxyResult},
frontend::{
authorization::{key_is_authorized, Authorization, RequestOrMethod, ResponseOrBytes},
rpc_proxy_ws::ProxyMode,
@ -570,6 +570,13 @@ impl ValidatedRequest {
Ok(())
}
pub fn add_error_response(&self, _err: &Web3ProxyError) {
self.error_response.store(true, atomic::Ordering::SeqCst);
// TODO: add actual response size
self.add_response(0);
}
pub fn add_response<'a, R: Into<ResponseOrBytes<'a>>>(&'a self, response: R) {
// TODO: fetch? set? should it be None in a Mutex? or a OnceCell?
let response = response.into();

@ -1286,8 +1286,20 @@ impl Web3Rpc {
// TODO: if we are inside the health checks and we aren't healthy yet. we need some sort of flag to force try_handle to not error
self.authorized_request(&web3_request, error_handler, true)
.await
let response = self
.authorized_request(&web3_request, error_handler, true)
.await;
match &response {
Ok(x) => {
// TODO: this is not efficient :(
let x = json!(x);
web3_request.add_response(&x)
}
Err(e) => web3_request.add_error_response(e),
}
response
}
pub async fn authorized_request<R: JsonRpcResultData>(

@ -570,7 +570,7 @@ impl RpcQueryStats {
if !error_response {
// force error_response to true
// this can happen when a try operator escapes and metadata.add_response() isn't called
trace!(
warn!(
"no response known, but no errors logged. investigate. {:?}",
metadata
);