From 1179e15842eb7764515440e24e67d240a21bcd93 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 23 May 2019 08:15:32 +0200 Subject: [PATCH] src/server/rest.rs: improve error handling --- src/server/rest.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/server/rest.rs b/src/server/rest.rs index 4ce7cf34..7ec5b0ca 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -239,10 +239,10 @@ pub fn handle_sync_api_request( let resp = params .and_then(move |params| { let mut delay = false; - let resp = match (info.handler.as_ref().unwrap())(params, info, &mut rpcenv) { + let resp = match (info.handler.as_ref().unwrap())(params, info, &mut rpcenv) { Ok(data) => (formatter.format_data)(data, &rpcenv), Err(err) => { - if let Some(httperr) = err.downcast_ref::() { + if let Some(httperr) = err.downcast_ref::() { if httperr.code == StatusCode::UNAUTHORIZED { delay = true; } } (formatter.format_error)(err) @@ -258,6 +258,9 @@ pub fn handle_sync_api_request( } else { Either::B(future::ok(resp)) } + }) + .or_else(move |err| { + Ok((formatter.format_error)(err)) }); Box::new(resp)