From 625253e49c88de46b05fee30d5a93f8972b34e94 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 23 Dec 2023 12:36:52 +0000 Subject: [PATCH] Get rid of the rest of the unwraps. --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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); } -- 2.30.2