well that option wasnt as clean as i wanted
This commit is contained in:
parent
bbeff03452
commit
bfef7a3eb0
@ -1441,7 +1441,7 @@ impl IntoResponse for Web3ProxyError {
|
||||
#[inline]
|
||||
/// TODO: maybe we don't want this anymore. maybe we want to require a web3_request?
|
||||
fn into_response(self) -> Response {
|
||||
self.into_response_with_id(Default::default(), RequestForError::None)
|
||||
self.into_response_with_id(Default::default(), None::<RequestForError>)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1465,11 +1465,15 @@ where
|
||||
}
|
||||
|
||||
impl Web3ProxyError {
|
||||
pub fn into_message<'a, R>(self, id: Option<Box<RawValue>>, web3_request: R) -> Message
|
||||
pub fn into_message<'a, R>(
|
||||
self,
|
||||
id: Option<Box<RawValue>>,
|
||||
request_for_error: Option<R>,
|
||||
) -> Message
|
||||
where
|
||||
R: Into<RequestForError<'a>>,
|
||||
{
|
||||
let (_, err) = self.as_response_parts(web3_request);
|
||||
let (_, err) = self.as_response_parts(request_for_error);
|
||||
|
||||
let id = id.unwrap_or_default();
|
||||
|
||||
|
@ -192,7 +192,7 @@ impl ResponseOrBytes<'_> {
|
||||
Self::Response(x) => x.num_bytes(),
|
||||
Self::Bytes(num_bytes) => *num_bytes,
|
||||
Self::Error(x) => {
|
||||
let (_, x) = x.as_response_parts(RequestForError::None);
|
||||
let (_, x) = x.as_response_parts(None::<RequestForError>);
|
||||
|
||||
x.num_bytes()
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use super::authorization::{ip_is_authorized, key_is_authorized};
|
||||
use super::request_id::RequestId;
|
||||
use super::rpc_proxy_ws::ProxyMode;
|
||||
use crate::errors::Web3ProxyError;
|
||||
use crate::errors::{RequestForError, Web3ProxyError};
|
||||
use crate::{app::App, jsonrpc::JsonRpcRequestEnum};
|
||||
use axum::extract::rejection::JsonRejection;
|
||||
use axum::extract::{Path, State};
|
||||
@ -92,14 +92,14 @@ async fn _proxy_web3_rpc(
|
||||
) -> Result<Response, Response> {
|
||||
// TODO: create a stat if they error. (but we haven't parsed rpc_key yet, so it needs some thought)
|
||||
let payload = payload
|
||||
.map_err(|e| Web3ProxyError::from(e).into_response_with_id(None, None))?
|
||||
.map_err(|e| Web3ProxyError::from(e).into_response_with_id(None, None::<RequestForError>))?
|
||||
.0;
|
||||
|
||||
let first_id = payload.first_id();
|
||||
|
||||
let authorization = ip_is_authorized(&app, ip, origin, proxy_mode)
|
||||
.await
|
||||
.map_err(|e| e.into_response_with_id(first_id.clone(), None))?;
|
||||
.map_err(|e| e.into_response_with_id(first_id.clone(), None::<RequestForError>))?;
|
||||
|
||||
let authorization = Arc::new(authorization);
|
||||
|
||||
@ -114,7 +114,7 @@ async fn _proxy_web3_rpc(
|
||||
let (status_code, response, rpcs) = app
|
||||
.proxy_web3_rpc(authorization, payload, Some(request_id))
|
||||
.await
|
||||
.map_err(|e| e.into_response_with_id(first_id, None))?;
|
||||
.map_err(|e| e.into_response_with_id(first_id, None::<RequestForError>))?;
|
||||
|
||||
let mut response = (status_code, response).into_response();
|
||||
|
||||
@ -300,19 +300,19 @@ async fn _proxy_web3_rpc_with_key(
|
||||
// TODO: DRY w/ proxy_web3_rpc
|
||||
// TODO: create a stat if they error. (but we haven't parsed rpc_key yet, so it needs some thought)
|
||||
let payload = payload
|
||||
.map_err(|e| Web3ProxyError::from(e).into_response_with_id(None, None))?
|
||||
.map_err(|e| Web3ProxyError::from(e).into_response_with_id(None, None::<RequestForError>))?
|
||||
.0;
|
||||
|
||||
let first_id = payload.first_id();
|
||||
|
||||
let rpc_key = rpc_key
|
||||
.parse()
|
||||
.map_err(|e: Web3ProxyError| e.into_response_with_id(first_id.clone(), None))?;
|
||||
let rpc_key = rpc_key.parse().map_err(|e: Web3ProxyError| {
|
||||
e.into_response_with_id(first_id.clone(), None::<RequestForError>)
|
||||
})?;
|
||||
|
||||
let authorization =
|
||||
key_is_authorized(&app, &rpc_key, ip, origin, proxy_mode, referer, user_agent)
|
||||
.await
|
||||
.map_err(|e| e.into_response_with_id(first_id.clone(), None))?;
|
||||
.map_err(|e| e.into_response_with_id(first_id.clone(), None::<RequestForError>))?;
|
||||
|
||||
let authorization = Arc::new(authorization);
|
||||
|
||||
@ -326,7 +326,7 @@ async fn _proxy_web3_rpc_with_key(
|
||||
let (status_code, response, rpcs) = app
|
||||
.proxy_web3_rpc(authorization, payload, Some(request_id))
|
||||
.await
|
||||
.map_err(|e| e.into_response_with_id(first_id, None))?;
|
||||
.map_err(|e| e.into_response_with_id(first_id, None::<RequestForError>))?;
|
||||
|
||||
let mut response = (status_code, response).into_response();
|
||||
|
||||
|
@ -448,7 +448,7 @@ async fn handle_socket_payload(
|
||||
let response_str = match response {
|
||||
Ok(x) => x.to_json_string().await?,
|
||||
Err(err) => {
|
||||
let (_, response_data) = err.as_response_parts(RequestForError::None);
|
||||
let (_, response_data) = err.as_response_parts(None::<RequestForError>);
|
||||
|
||||
let response = ParsedResponse::from_response_data(response_data, response_id);
|
||||
|
||||
@ -498,7 +498,7 @@ async fn read_web3_socket(
|
||||
Ok((m, s)) => (m, Some(s)),
|
||||
Err(err) => {
|
||||
// TODO: how can we get the id out of the payload?
|
||||
let m = err.into_message(None, None);
|
||||
let m = err.into_message(None, None::<RequestForError>);
|
||||
(m, None)
|
||||
}
|
||||
}
|
||||
@ -532,7 +532,7 @@ async fn read_web3_socket(
|
||||
Ok((m, s)) => (m, Some(s)),
|
||||
Err(err) => {
|
||||
// TODO: how can we get the id out of the payload?
|
||||
let m = err.into_message(None, None);
|
||||
let m = err.into_message(None, None::<RequestForError>);
|
||||
(m, None)
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::LooseId;
|
||||
use crate::app::App;
|
||||
use crate::errors::{Web3ProxyError, RequestForError};
|
||||
use crate::errors::{RequestForError, Web3ProxyError};
|
||||
use crate::frontend::authorization::{Authorization, RequestOrMethod};
|
||||
use crate::jsonrpc::ValidatedRequest;
|
||||
use axum::response::Response as AxumResponse;
|
||||
@ -142,7 +142,7 @@ impl JsonRpcRequestEnum {
|
||||
|
||||
request.add_response(&response);
|
||||
|
||||
let response = response.into_response_with_id(Some(err_id), RequestForError::None);
|
||||
let response = response.into_response_with_id(Some(err_id), None::<RequestForError>);
|
||||
|
||||
// TODO: variable duration depending on the IP
|
||||
sleep(duration).await;
|
||||
|
Loading…
Reference in New Issue
Block a user