chiark / gitweb /
Get rid of the rest of the unwraps.
authorSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 12:36:52 +0000 (12:36 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 12:36:52 +0000 (12:36 +0000)
src/main.rs

index 04f89adc9664f2efb7ea692e49cb82df966ebbec..550e9da232ae0746039a16ca5a01d94ce1d2c4b5 100644 (file)
@@ -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);
     }