From: Simon Tatham Date: Sat, 23 Dec 2023 12:36:52 +0000 (+0000) Subject: Get rid of the rest of the unwraps. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=625253e49c88de46b05fee30d5a93f8972b34e94;p=mastodonochrome.git Get rid of the rest of the unwraps. --- diff --git a/src/main.rs b/src/main.rs index 04f89ad..550e9da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ // use mastodonochrome::types::*; +use mastodonochrome::OurError; use mastodonochrome::auth::AuthConfig; use std::io::Read; @@ -6,13 +7,18 @@ fn main() -> Result<(), mastodonochrome::OurError> { let auth = AuthConfig::load()?; let client = reqwest::blocking::Client::new(); - let mut req = client.get(auth.instance_url + "/api/v1/streaming/user") - .bearer_auth(auth.user_token) - .send().unwrap(); + let req = client.get(auth.instance_url + "/api/v1/streaming/user") + .bearer_auth(auth.user_token); + + let mut rsp = match req.send() { + Err(e) => Err(OurError::Fatal( + format!("unable to make HTTP request: {}", e))), + Ok(d) => Ok(d), + }?; const BUFSIZE: usize = 4096; let mut buf: [u8; BUFSIZE] = [0; BUFSIZE]; - while let Ok(sz) = req.read(&mut buf) { + while let Ok(sz) = rsp.read(&mut buf) { let read = &buf[..sz]; dbg!(read); }