From 416feedf83d698b5ed5d8a7b1b8c31f70840d8b9 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sun, 6 Sep 2020 03:33:44 -0400 Subject: [PATCH] better handling of json parse errors --- src/proxy.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/proxy.rs b/src/proxy.rs index 5fc5368..6c093ba 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -127,10 +127,16 @@ async fn proxy(client: Client>>, return bad_request("auth not found"); } - let auth : Ping = serde_json::from_str(flex_auth.unwrap().to_string().as_str()).unwrap(); - if !auth.verify(auth_token.clone()) { - error!("proxy: invalid auth"); - return bad_request("invalid auth"); + let auth_result = serde_json::from_str(flex_auth.unwrap().to_string().as_str()); + if auth_result.is_err() { + error!("proxy: error parsing auth: {:?}", auth_result.err()); + return bad_request("error parsing auth"); + } else { + let auth: Ping = auth_result.unwrap(); + if !auth.verify(auth_token.clone()) { + error!("proxy: invalid auth"); + return bad_request("invalid auth"); + } } let host = host.unwrap();