allow ids in errors
This commit is contained in:
parent
600df2cd3a
commit
c8e62624cf
@ -10,7 +10,7 @@ use futures::stream::StreamExt;
|
|||||||
use futures::Future;
|
use futures::Future;
|
||||||
use linkedhashmap::LinkedHashMap;
|
use linkedhashmap::LinkedHashMap;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use redis_cell_client::{bb8, RedisCellClient, RedisClientPool, RedisConnectionManager};
|
use redis_cell_client::{bb8, RedisCellClient, RedisConnectionManager};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
@ -444,8 +444,6 @@ impl Web3Connection {
|
|||||||
let mut interval = interval(Duration::from_secs(60));
|
let mut interval = interval(Duration::from_secs(60));
|
||||||
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
|
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
|
||||||
|
|
||||||
// TODO: create a filter
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// TODO: actually do something here
|
// TODO: actually do something here
|
||||||
/*
|
/*
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
use axum::{http::StatusCode, response::IntoResponse, Json};
|
use axum::{http::StatusCode, response::IntoResponse, Json};
|
||||||
use serde_json::value::RawValue;
|
use serde_json::value::RawValue;
|
||||||
use tracing::warn;
|
|
||||||
|
|
||||||
use crate::jsonrpc::JsonRpcForwardedResponse;
|
use crate::jsonrpc::JsonRpcForwardedResponse;
|
||||||
|
|
||||||
pub async fn handler_404() -> impl IntoResponse {
|
pub async fn handler_404() -> impl IntoResponse {
|
||||||
let err = anyhow::anyhow!("nothing to see here");
|
let err = anyhow::anyhow!("nothing to see here");
|
||||||
|
|
||||||
handle_anyhow_error(Some(StatusCode::NOT_FOUND), err).await
|
handle_anyhow_error(Some(StatusCode::NOT_FOUND), None, err).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// handle errors by converting them into something that implements `IntoResponse`
|
/// handle errors by converting them into something that implements `IntoResponse`
|
||||||
@ -15,13 +14,16 @@ pub async fn handler_404() -> impl IntoResponse {
|
|||||||
/// TODO: i think we want a custom result type instead. put the anyhow result inside. then `impl IntoResponse for CustomResult`
|
/// TODO: i think we want a custom result type instead. put the anyhow result inside. then `impl IntoResponse for CustomResult`
|
||||||
pub async fn handle_anyhow_error(
|
pub async fn handle_anyhow_error(
|
||||||
code: Option<StatusCode>,
|
code: Option<StatusCode>,
|
||||||
|
id: Option<Box<RawValue>>,
|
||||||
err: anyhow::Error,
|
err: anyhow::Error,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let id = RawValue::from_string("null".to_string()).unwrap();
|
// TODO: we might have an id. like if this is for rate limiting, we can use it
|
||||||
|
let id = id.unwrap_or_else(|| RawValue::from_string("null".to_string()).unwrap());
|
||||||
|
|
||||||
let err = JsonRpcForwardedResponse::from_anyhow_error(err, id);
|
let err = JsonRpcForwardedResponse::from_anyhow_error(err, id);
|
||||||
|
|
||||||
warn!("Responding with error: {:?}", err);
|
// TODO: logs here are too verbose. emit a stat
|
||||||
|
// warn!("Responding with error: {:?}", err);
|
||||||
|
|
||||||
let code = code.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
|
let code = code.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
|
@ -16,8 +16,10 @@ pub async fn proxy_web3_rpc(
|
|||||||
if rate_limiter.throttle_key(&rate_limiter_key).await.is_err() {
|
if rate_limiter.throttle_key(&rate_limiter_key).await.is_err() {
|
||||||
// TODO: set headers so they know when they can retry
|
// TODO: set headers so they know when they can retry
|
||||||
// warn!(?ip, "public rate limit exceeded");
|
// warn!(?ip, "public rate limit exceeded");
|
||||||
|
// TODO: use their id if possible
|
||||||
return handle_anyhow_error(
|
return handle_anyhow_error(
|
||||||
Some(StatusCode::TOO_MANY_REQUESTS),
|
Some(StatusCode::TOO_MANY_REQUESTS),
|
||||||
|
None,
|
||||||
anyhow::anyhow!("too many requests"),
|
anyhow::anyhow!("too many requests"),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -29,6 +31,6 @@ pub async fn proxy_web3_rpc(
|
|||||||
|
|
||||||
match app.proxy_web3_rpc(payload).await {
|
match app.proxy_web3_rpc(payload).await {
|
||||||
Ok(response) => (StatusCode::OK, Json(&response)).into_response(),
|
Ok(response) => (StatusCode::OK, Json(&response)).into_response(),
|
||||||
Err(err) => handle_anyhow_error(None, err).await.into_response(),
|
Err(err) => handle_anyhow_error(None, None, err).await.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user