Replace http_server
unwrap with 500 error
This commit is contained in:
parent
3a65f84b12
commit
ed4d7aa44a
@ -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,
|
||||
|
@ -108,3 +108,11 @@ pub fn start_service<T: BeaconChainTypes + 'static>(
|
||||
|
||||
shutdown_trigger
|
||||
}
|
||||
|
||||
/// Helper function for mapping a failure to read state to a 500 server error.
|
||||
fn map_persistent_err_to_500(e: persistent::PersistentError) -> iron::error::IronError {
|
||||
iron::error::IronError {
|
||||
error: Box::new(e),
|
||||
response: iron::Response::with(iron::status::Status::InternalServerError),
|
||||
}
|
||||
}
|
||||
|
@ -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::{status::Status, Handler, IronResult, Request, Response};
|
||||
@ -23,7 +23,9 @@ pub fn build_handler<T: BeaconChainTypes + 'static>(
|
||||
///
|
||||
/// Returns a text string containing all metrics.
|
||||
fn handle_metrics<T: BeaconChainTypes + 'static>(req: &mut Request) -> IronResult<Response> {
|
||||
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 r = Registry::new();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user