From 2b5c0df9e56a751f4e2ef0fd33274f9b8b6157a7 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 3 Dec 2020 23:10:08 +0000 Subject: [PATCH] Validators endpoint status code (#2040) ## Issue Addressed Resolves #2035 ## Proposed Changes Update 405's to 400's for failures when we are parsing path params. ## Additional Info Haven't updated the same for non-standard endpoints Co-authored-by: realbigsean --- beacon_node/http_api/src/lib.rs | 52 ++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 8c3902fcd4d..159a3d2f041 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -388,12 +388,10 @@ pub fn serve( let beacon_states_path = eth1_v1 .and(warp::path("beacon")) .and(warp::path("states")) - .and(warp::path::param::().or_else(|_| { - blocking_task(|| { - Err(warp_utils::reject::custom_bad_request( - "Invalid state ID".to_string(), - )) - }) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid state ID".to_string(), + )) })) .and(chain_filter.clone()); @@ -551,7 +549,11 @@ pub fn serve( let get_beacon_state_validators_id = beacon_states_path .clone() .and(warp::path("validators")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid validator ID".to_string(), + )) + })) .and(warp::path::end()) .and_then( |state_id: StateId, chain: Arc>, validator_id: ValidatorId| { @@ -760,7 +762,11 @@ pub fn serve( let get_beacon_headers_block_id = eth1_v1 .and(warp::path("beacon")) .and(warp::path("headers")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid block ID".to_string(), + )) + })) .and(warp::path::end()) .and(chain_filter.clone()) .and_then(|block_id: BlockId, chain: Arc>| { @@ -845,7 +851,11 @@ pub fn serve( let beacon_blocks_path = eth1_v1 .and(warp::path("beacon")) .and(warp::path("blocks")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid block ID".to_string(), + )) + })) .and(chain_filter.clone()); // GET beacon/blocks/{block_id} @@ -1222,7 +1232,11 @@ pub fn serve( .and(warp::path("debug")) .and(warp::path("beacon")) .and(warp::path("states")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid state ID".to_string(), + )) + })) .and(warp::path::end()) .and(chain_filter.clone()) .and_then(|state_id: StateId, chain: Arc>| { @@ -1531,7 +1545,11 @@ pub fn serve( .and(warp::path("validator")) .and(warp::path("duties")) .and(warp::path("proposer")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid epoch".to_string(), + )) + })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) .and(chain_filter.clone()) @@ -1596,7 +1614,11 @@ pub fn serve( let get_validator_blocks = eth1_v1 .and(warp::path("validator")) .and(warp::path("blocks")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid slot".to_string(), + )) + })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) .and(warp::query::()) @@ -1683,7 +1705,11 @@ pub fn serve( .and(warp::path("validator")) .and(warp::path("duties")) .and(warp::path("attester")) - .and(warp::path::param::()) + .and(warp::path::param::().or_else(|_| async { + Err(warp_utils::reject::custom_bad_request( + "Invalid epoch".to_string(), + )) + })) .and(warp::path::end()) .and(not_while_syncing_filter.clone()) .and(warp::body::json())