Replace http_server unwrap with 500 error

This commit is contained in:
Paul Hauner
2019-05-27 17:09:16 +10:00
parent 3a65f84b12
commit ed4d7aa44a
3 changed files with 16 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
use crate::key::BeaconChainKey;
use crate::{key::BeaconChainKey, map_persistent_err_to_500};
use beacon_chain::{BeaconChain, BeaconChainTypes};
use iron::prelude::*;
use iron::{
@@ -58,8 +58,9 @@ impl AfterMiddleware for SetJsonContentType {
}
fn handle_fork<T: BeaconChainTypes + 'static>(req: &mut Request) -> IronResult<Response> {
// TODO: investigate unwrap - I'm _guessing_ we'll never hit it but we should check to be sure.
let beacon_chain = req.get::<Read<BeaconChainKey<T>>>().unwrap();
let beacon_chain = req
.get::<Read<BeaconChainKey<T>>>()
.map_err(map_persistent_err_to_500)?;
let response = json!({
"fork": beacon_chain.head().beacon_state.fork,