Use ? instead of match where appropriate

This commit is contained in:
Neshura 2023-08-03 21:38:22 +02:00
parent 17d375a5dc
commit 7f717d30b7
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
2 changed files with 10 additions and 28 deletions

View file

@ -102,12 +102,9 @@ impl Config {
let mut post_queue: Vec<CreatePost> = vec![]; let mut post_queue: Vec<CreatePost> = vec![];
match self.feeds.iter().map(|feed| { match self.feeds.iter().map(|feed| {
let res = match CLIENT let res = CLIENT
.get(feed.feed_url.clone()) .get(feed.feed_url.clone())
.send() { .send()?.text()?;
Ok(data) => data.text().unwrap(),
Err(e) => return Err(e)
};
let data: FeedData = serde_json::from_str(&res).unwrap(); let data: FeedData = serde_json::from_str(&res).unwrap();
@ -281,13 +278,10 @@ impl CommunitiesVector {
..Default::default() ..Default::default()
}; };
let res = match CLIENT let res = CLIENT
.get(base.clone() + "/api/v3/community/list") .get(base.clone() + "/api/v3/community/list")
.query(&params) .query(&params)
.send() { .send()?.text()?;
Ok(data) => data.text().unwrap(),
Err(e) => return Err(e)
};
let site_data: ListCommunitiesResponse = serde_json::from_str(&res).unwrap(); let site_data: ListCommunitiesResponse = serde_json::from_str(&res).unwrap();

View file

@ -57,13 +57,10 @@ impl Bot {
totp_2fa_token: None, totp_2fa_token: None,
}; };
let res = match CLIENT let res = CLIENT
.post(self.config.instance.clone() + "/api/v3/user/login") .post(self.config.instance.clone() + "/api/v3/user/login")
.json(&login_params) .json(&login_params)
.send() { .send()?;
Ok(data) => data,
Err(e) => return Err(e),
};
if res.status() == StatusCode::OK { if res.status() == StatusCode::OK {
@ -84,13 +81,10 @@ impl Bot {
/// * `return` : Returns true if Post was succesful, false otherwise /// * `return` : Returns true if Post was succesful, false otherwise
#[warn(unused_results)] #[warn(unused_results)]
pub(crate) fn post(&mut self, post_data: CreatePost) -> Result<(), reqwest::Error> { pub(crate) fn post(&mut self, post_data: CreatePost) -> Result<(), reqwest::Error> {
let res = match CLIENT let res = CLIENT
.post(self.config.instance.clone() + "/api/v3/post") .post(self.config.instance.clone() + "/api/v3/post")
.json(&post_data) .json(&post_data)
.send() { .send()?;
Ok(data) => data,
Err(e) => return Err(e)
};
// TODO: process res to get info about if post was successfuly (mostly if jwt token was valid) // TODO: process res to get info about if post was successfuly (mostly if jwt token was valid)
@ -106,20 +100,14 @@ impl Bot {
println!("Reloading Config"); println!("Reloading Config");
*prev_time = self.start_time; *prev_time = self.start_time;
self.config.load(); self.config.load();
match self.community_ids.load(&self.auth, &self.config.instance) { self.community_ids.load(&self.auth, &self.config.instance)?;
Ok(_) => {},
Err(e) => return Err(e)
};
println!("Done!"); println!("Done!");
} }
// Start the polling process // Start the polling process
// Get all feed URLs (use cache) // Get all feed URLs (use cache)
println!("Checking Feeds"); println!("Checking Feeds");
let post_queue: Vec<CreatePost> = match self.config.check_feeds(&mut self.post_history, &self.community_ids, &self.auth) { let post_queue: Vec<CreatePost> = self.config.check_feeds(&mut self.post_history, &self.community_ids, &self.auth)?;
Ok(data) => data,
Err(e) => return Err(e)
};
println!("Done!"); println!("Done!");
post_queue.iter().for_each(|post| { post_queue.iter().for_each(|post| {