Overhaul Error handling (Option instead of Result<T, ()> + Logging changes

This commit is contained in:
Neshura 2024-05-07 23:49:55 +02:00
parent 5d708bdb82
commit b6f5c38e4a
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
5 changed files with 146 additions and 96 deletions
src/fetchers

View file

@ -224,7 +224,7 @@ impl FetcherTrait for JNovelFetcher {
.or_insert(new_post_info);
}
if let Some(prepub_info) = get_latest_prepub(&volume.slug).await? {
if let Some(prepub_info) = get_latest_prepub(&volume.slug).await {
let prepub_post_info = PostInfo {
post_type: Some(PostType::Chapter),
part: Some(new_part_info),
@ -252,7 +252,7 @@ impl FetcherTrait for JNovelFetcher {
}
async fn get_latest_prepub(volume_slug: &str) -> Result<Option<PostInfoInner>, ()> {
async fn get_latest_prepub(volume_slug: &str) -> Option<PostInfoInner> {
let response = match HTTP_CLIENT
.get(api_url!() + "/volumes/" + volume_slug + "/parts?format=json")
.send()
@ -263,13 +263,13 @@ async fn get_latest_prepub(volume_slug: &str) -> Result<Option<PostInfoInner>, (
Err(e) => {
let err_msg = format!("While getting latest PrePub: {e}");
error!(err_msg);
return Err(());
return None;
}
},
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return Err(());
return None;
}
};
@ -278,7 +278,7 @@ async fn get_latest_prepub(volume_slug: &str) -> Result<Option<PostInfoInner>, (
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return Err(());
return None;
}
};
volume_prepub_parts_data.parts.reverse(); // Makes breaking out of the parts loop easier
@ -300,5 +300,5 @@ async fn get_latest_prepub(volume_slug: &str) -> Result<Option<PostInfoInner>, (
});
}
Ok(post_details)
post_details
}