polish small things while reading through the code

This commit is contained in:
Bryan Stitt 2022-08-10 06:22:49 +00:00
parent 3c56dd6afc
commit 44365d7b39
3 changed files with 5 additions and 2 deletions

View File

@ -72,7 +72,7 @@ fn run(
rt.block_on(async {
let (app, app_handle) = Web3ProxyApp::spawn(app_config, num_workers).await?;
let frontend_handle = tokio::spawn(frontend::run(cli_config.port, app));
let frontend_handle = tokio::spawn(frontend::serve(cli_config.port, app));
// if everything is working, these should both run forever
// TODO: try_join these instead? use signal_shutdown here?

View File

@ -17,7 +17,8 @@ use tracing::info;
use crate::app::Web3ProxyApp;
pub async fn run(port: u16, proxy_app: Arc<Web3ProxyApp>) -> anyhow::Result<()> {
///
pub async fn serve(port: u16, proxy_app: Arc<Web3ProxyApp>) -> anyhow::Result<()> {
// build our application with a route
// order most to least common
let app = Router::new()
@ -50,6 +51,7 @@ pub async fn run(port: u16, proxy_app: Arc<Web3ProxyApp>) -> anyhow::Result<()>
/// Tokio signal handler that will wait for a user to press CTRL+C.
/// We use this in our hyper `Server` method `with_graceful_shutdown`.
async fn signal_shutdown() {
info!("ctrl-c to quit");
tokio::signal::ctrl_c()
.await
.expect("expect tokio signal ctrl-c");

View File

@ -154,6 +154,7 @@ pub async fn handle_rate_limit_error_response(
Ok(RateLimitResult::RateLimitExceeded) => Some(handle_anyhow_error(
Some(StatusCode::TOO_MANY_REQUESTS),
None,
// TODO: how can we attach context here? maybe add a request id tracing field?
anyhow::anyhow!("rate limit exceeded"),
)),
Ok(RateLimitResult::UnknownKey) => Some(handle_anyhow_error(