From 32931f54d63ac58eef7663c23c277b7b9788bae9 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 27 Apr 2022 13:28:13 -0700 Subject: [PATCH] don't expect/panic crash whole bot on malformed json --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index de2a1c8..1b9a2eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,9 +117,10 @@ impl UpdateBot { o: 1, d: resp_message, }; - let response_json = - serde_json::to_string(&response).expect("Error parsing json response"); - cwtch.send_message(&profile.handle, convo_id, &response_json); + match serde_json::to_string(&response) { + OK(response_json) => cwtch.send_message(&profile.handle, convo_id, &response_json), + Err(e) => println!("Error parsing json response: {}", e.to_string()), + } } } }