diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-08-19 15:02:53 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-08-19 15:02:53 +0200 |
commit | cabd6e0a688399b33e2df6960f55aeb8134993c3 (patch) | |
tree | ff8dcdca626591dcd23966ccbe53fc93541f9b8f /examples | |
parent | 91d5ee5a8ed9b3e235019da3f74b60d40dad3792 (diff) | |
download | rust-zotapi-cabd6e0a688399b33e2df6960f55aeb8134993c3.tar.gz rust-zotapi-cabd6e0a688399b33e2df6960f55aeb8134993c3.tar.bz2 rust-zotapi-cabd6e0a688399b33e2df6960f55aeb8134993c3.zip |
Update example to handle error from channel stream.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hubzilla-channel-stream.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/examples/hubzilla-channel-stream.rs b/examples/hubzilla-channel-stream.rs index f0cab19..6820341 100644 --- a/examples/hubzilla-channel-stream.rs +++ b/examples/hubzilla-channel-stream.rs @@ -8,19 +8,31 @@ use std::env; fn main() { dotenv().ok(); - let site = env::var("SITE").unwrap(); - let user = env::var("USER").unwrap(); - let password = env::var("PASSWORD").unwrap(); + let site = env::var("SITE").expect("SITE variable expected"); + let user = env::var("USER").expect("USER variable expected"); + let password = env::var("PASSWORD").expect("PASSWORD variable expected"); let client = zotapi::client(&site, &user, &password); - match serde_json::from_str(&client.channel_stream()).unwrap() { - Value::Array(v) => { - for item in v.into_iter() { - println!("{} {} {}", item["title"], item["type"], item["author"]["name"]); + match client.channel_stream() { + Ok(payload) => { + println!("Raw payload: {}", payload); + + match serde_json::from_str(&payload) { + Ok(Value::Array(v)) => { + for item in v.into_iter() { + println!("{} {} {}", item["title"], item["type"], item["author"]["name"]); + } + }, + Ok(_) => { + println!("Wrong type returned, expected an array.") + }, + Err(e) => { + println!("Error: {}", e); + } } }, - _ => { - println!("Expected an array, really..."); + Err(e) => { + println!("Error getting channel stream: {:?}", e); } } } |