Reduce number of unwwaps in api crate (#2681)

* Reduce number of unwwaps in api crate

* Format use section
This commit is contained in:
hashmap
2019-03-18 19:34:35 +01:00
committed by GitHub
parent 2b218f2dc3
commit 7fad5b040f
17 changed files with 165 additions and 123 deletions
+5 -2
View File
@@ -2,7 +2,7 @@ use grin_api as api;
use grin_util as util;
use crate::api::*;
use hyper::{Body, Request};
use hyper::{Body, Request, StatusCode};
use std::net::SocketAddr;
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use std::sync::Arc;
@@ -43,7 +43,10 @@ impl Handler for CounterMiddleware {
mut handlers: Box<dyn Iterator<Item = HandlerObj>>,
) -> ResponseFuture {
self.counter.fetch_add(1, Ordering::SeqCst);
handlers.next().unwrap().call(req, handlers)
match handlers.next() {
Some(h) => h.call(req, handlers),
None => return response(StatusCode::INTERNAL_SERVER_ERROR, "no handler found"),
}
}
}