From 1126803cab05ba7db2cf7d6687a6878c6810292a Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 12 Sep 2020 04:47:41 -0400 Subject: [PATCH] don't create messages on zero-length or non-200 --- src/vocodes_api.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/vocodes_api.rs b/src/vocodes_api.rs index 4cda4cd..442d670 100644 --- a/src/vocodes_api.rs +++ b/src/vocodes_api.rs @@ -1,14 +1,17 @@ +use anyhow::Result as AnyhowResult; +use anyhow::bail; use hyper::Body; use hyper::Client as HyperClient; use hyper::Request; use hyper_tls::HttpsConnector; +use log::{error, debug, info, warn}; const VOCODES_SPEAK_ENDPOINT : &'static str = "http://mumble.stream/speak"; -pub async fn fetch(text: &str, speaker: &str) -> Result, Box> { +pub async fn fetch(text: &str, speaker: &str) -> AnyhowResult> { let mut request = format!("{{\"speaker\": \"{}\", \"text\": \"{}\"}}", speaker, text); - println!("Req: {}", request); + debug!("Req: {}", request); let https = HttpsConnector::new(); let client = HyperClient::builder() @@ -25,12 +28,20 @@ pub async fn fetch(text: &str, speaker: &str) -> Result, Box