Utilize cascading errors instead of bools

This commit is contained in:
Neshura 2023-07-31 19:50:22 +02:00
parent d31f291e26
commit 210ca895db
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
2 changed files with 51 additions and 42 deletions
src/config

View file

@ -98,15 +98,15 @@ impl Config {
}
pub(crate) fn check_feeds(&mut self, post_history: &mut Vec<PrevPost>
, community_ids: &CommunitiesVector, auth: &Sensitive<String>) -> Result<Vec<CreatePost>, ()> {
, community_ids: &CommunitiesVector, auth: &Sensitive<String>) -> Result<Vec<CreatePost>, reqwest::Error> {
let mut post_queue: Vec<CreatePost> = vec![];
self.feeds.iter().for_each(|feed| {
match self.feeds.iter().map(|feed| {
let res = match CLIENT
.get(feed.feed_url.clone())
.send() {
Ok(data) => data.text().unwrap(),
Err(_) => return ()
Err(e) => return Err(e)
};
let data: FeedData = serde_json::from_str(&res).unwrap();
@ -152,7 +152,11 @@ impl Config {
}
}
sleep(time::Duration::from_millis(100)); // Should prevent dos-ing J-Novel servers
});
return Ok(());
}).collect() {
Ok(()) => {}
Err(e) => return Err(e)
}
PrevPost::save(&post_history);
return Ok(post_queue);
@ -270,7 +274,7 @@ impl CommunitiesVector {
}
#[warn(unused_results)]
pub(crate) fn load(&mut self, auth: &Sensitive<String>, base: &String) -> bool {
pub(crate) fn load(&mut self, auth: &Sensitive<String>, base: &String) -> Result<(), reqwest::Error> {
let params = ListCommunities {
auth: Some(auth.clone()),
type_: Some(ListingType::Local),
@ -281,10 +285,8 @@ impl CommunitiesVector {
.get(base.clone() + "/api/v3/community/list")
.query(&params)
.send() {
Ok(data) => {
data.text().unwrap()
}
Err(_) => {return false}
Ok(data) => data.text().unwrap(),
Err(e) => return Err(e)
};
let site_data: ListCommunitiesResponse = serde_json::from_str(&res).unwrap();
@ -297,7 +299,7 @@ impl CommunitiesVector {
});
self.ids = ids;
return true;
return Ok(());
}
pub(crate) fn find(&self, name: &LemmyCommunities) -> CommunityId {