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 <seananderson33@gmail.com>
This commit is contained in:
realbigsean 2020-12-03 23:10:08 +00:00
parent e06d040b5d
commit 2b5c0df9e5

View File

@ -388,12 +388,10 @@ pub fn serve<T: BeaconChainTypes>(
let beacon_states_path = eth1_v1 let beacon_states_path = eth1_v1
.and(warp::path("beacon")) .and(warp::path("beacon"))
.and(warp::path("states")) .and(warp::path("states"))
.and(warp::path::param::<StateId>().or_else(|_| { .and(warp::path::param::<StateId>().or_else(|_| async {
blocking_task(|| {
Err(warp_utils::reject::custom_bad_request( Err(warp_utils::reject::custom_bad_request(
"Invalid state ID".to_string(), "Invalid state ID".to_string(),
)) ))
})
})) }))
.and(chain_filter.clone()); .and(chain_filter.clone());
@ -551,7 +549,11 @@ pub fn serve<T: BeaconChainTypes>(
let get_beacon_state_validators_id = beacon_states_path let get_beacon_state_validators_id = beacon_states_path
.clone() .clone()
.and(warp::path("validators")) .and(warp::path("validators"))
.and(warp::path::param::<ValidatorId>()) .and(warp::path::param::<ValidatorId>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid validator ID".to_string(),
))
}))
.and(warp::path::end()) .and(warp::path::end())
.and_then( .and_then(
|state_id: StateId, chain: Arc<BeaconChain<T>>, validator_id: ValidatorId| { |state_id: StateId, chain: Arc<BeaconChain<T>>, validator_id: ValidatorId| {
@ -760,7 +762,11 @@ pub fn serve<T: BeaconChainTypes>(
let get_beacon_headers_block_id = eth1_v1 let get_beacon_headers_block_id = eth1_v1
.and(warp::path("beacon")) .and(warp::path("beacon"))
.and(warp::path("headers")) .and(warp::path("headers"))
.and(warp::path::param::<BlockId>()) .and(warp::path::param::<BlockId>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid block ID".to_string(),
))
}))
.and(warp::path::end()) .and(warp::path::end())
.and(chain_filter.clone()) .and(chain_filter.clone())
.and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| { .and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| {
@ -845,7 +851,11 @@ pub fn serve<T: BeaconChainTypes>(
let beacon_blocks_path = eth1_v1 let beacon_blocks_path = eth1_v1
.and(warp::path("beacon")) .and(warp::path("beacon"))
.and(warp::path("blocks")) .and(warp::path("blocks"))
.and(warp::path::param::<BlockId>()) .and(warp::path::param::<BlockId>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid block ID".to_string(),
))
}))
.and(chain_filter.clone()); .and(chain_filter.clone());
// GET beacon/blocks/{block_id} // GET beacon/blocks/{block_id}
@ -1222,7 +1232,11 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path("debug")) .and(warp::path("debug"))
.and(warp::path("beacon")) .and(warp::path("beacon"))
.and(warp::path("states")) .and(warp::path("states"))
.and(warp::path::param::<StateId>()) .and(warp::path::param::<StateId>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid state ID".to_string(),
))
}))
.and(warp::path::end()) .and(warp::path::end())
.and(chain_filter.clone()) .and(chain_filter.clone())
.and_then(|state_id: StateId, chain: Arc<BeaconChain<T>>| { .and_then(|state_id: StateId, chain: Arc<BeaconChain<T>>| {
@ -1531,7 +1545,11 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path("validator")) .and(warp::path("validator"))
.and(warp::path("duties")) .and(warp::path("duties"))
.and(warp::path("proposer")) .and(warp::path("proposer"))
.and(warp::path::param::<Epoch>()) .and(warp::path::param::<Epoch>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid epoch".to_string(),
))
}))
.and(warp::path::end()) .and(warp::path::end())
.and(not_while_syncing_filter.clone()) .and(not_while_syncing_filter.clone())
.and(chain_filter.clone()) .and(chain_filter.clone())
@ -1596,7 +1614,11 @@ pub fn serve<T: BeaconChainTypes>(
let get_validator_blocks = eth1_v1 let get_validator_blocks = eth1_v1
.and(warp::path("validator")) .and(warp::path("validator"))
.and(warp::path("blocks")) .and(warp::path("blocks"))
.and(warp::path::param::<Slot>()) .and(warp::path::param::<Slot>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid slot".to_string(),
))
}))
.and(warp::path::end()) .and(warp::path::end())
.and(not_while_syncing_filter.clone()) .and(not_while_syncing_filter.clone())
.and(warp::query::<api_types::ValidatorBlocksQuery>()) .and(warp::query::<api_types::ValidatorBlocksQuery>())
@ -1683,7 +1705,11 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path("validator")) .and(warp::path("validator"))
.and(warp::path("duties")) .and(warp::path("duties"))
.and(warp::path("attester")) .and(warp::path("attester"))
.and(warp::path::param::<Epoch>()) .and(warp::path::param::<Epoch>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid epoch".to_string(),
))
}))
.and(warp::path::end()) .and(warp::path::end())
.and(not_while_syncing_filter.clone()) .and(not_while_syncing_filter.clone())
.and(warp::body::json()) .and(warp::body::json())