diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt index 71659efc3..6599ef5b4 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt @@ -125,11 +125,6 @@ private fun rethrowExactly(response: HttpResponse, body: Either throw NotLoggedInException() "3" -> throw NoHathClientException() "4" -> throw InsufficientFundsException() - is String if message.startsWith('5') -> throw IpBannedException(message.drop(1)) + is String if message.isNotEmpty() -> { + when (message[0]) { + '5' -> throw IpBannedException(message.substring(1)) + '6' -> throw EhException(message.substring(1)) + } + } } } diff --git a/app/src/main/rust/src/ffi/jvm.rs b/app/src/main/rust/src/ffi/jvm.rs index 96de356a3..4b8fb45c8 100644 --- a/app/src/main/rust/src/ffi/jvm.rs +++ b/app/src/main/rust/src/ffi/jvm.rs @@ -245,7 +245,7 @@ where { parse_raw_marshal_inplace(env, str, limit, |html| { let mut dom = tl::parse(html, options)?; - ensure!(dom.version().is_some(), EhError::Error(html.to_string())); + ensure!(dom.version().is_some(), EhError::IpBanned(html.to_string())); f(&mut dom, html) }) } diff --git a/app/src/main/rust/src/lib.rs b/app/src/main/rust/src/lib.rs index 18c321dfb..18e62ea01 100644 --- a/app/src/main/rust/src/lib.rs +++ b/app/src/main/rust/src/lib.rs @@ -74,6 +74,7 @@ enum EhError { NeedLogin, NoHathClient, InsufficientFunds, + IpBanned(String), Error(String), } @@ -85,7 +86,8 @@ impl Display for EhError { EhError::NeedLogin => "2", EhError::NoHathClient => "3", EhError::InsufficientFunds => "4", - EhError::Error(s) => &format!("5{s}"), + EhError::IpBanned(s) => &format!("5{s}"), + EhError::Error(s) => &format!("6{s}"), }; f.write_str(msg) } diff --git a/app/src/main/rust/src/parser/detail.rs b/app/src/main/rust/src/parser/detail.rs index 9024b9a5e..2cc951bbc 100644 --- a/app/src/main/rust/src/parser/detail.rs +++ b/app/src/main/rust/src/parser/detail.rs @@ -233,15 +233,11 @@ fn parse_detail(gd: &mut GalleryDetail, dom: &VDom, parser: &Parser, body: &str) pub fn parse_gallery_detail(dom: &mut VDom, body: &str) -> Result { let parser = dom.parser(); - let error = get_vdom_first_element_by_class_name(dom, "d"); - if let Some(tag) = error.and_then(|n| get_first_child(n.as_tag()?, parser)) { - let node = tag.children().top()[0].get(parser).unwrap(); - bail!(EhError::Error(node.inner_text(parser).to_string())); - } let mut gallery_detail = GalleryDetail { - tagGroups: parse_tag_groups(dom, parser, false)?, + // Check availability in `parse_preview_list` as that will be called independently previewList: parse_preview_list(dom, parser)?, + tagGroups: parse_tag_groups(dom, parser, false)?, comments: parse_comments(dom)?, ..Default::default() }; @@ -474,6 +470,13 @@ pub fn parse_pages(dom: &VDom, parser: &Parser) -> Result { } pub fn parse_preview_list(dom: &VDom, parser: &Parser) -> Result> { + // Check Gallery Not Available + let error = get_vdom_first_element_by_class_name(dom, "d"); + if let Some(tag) = error.and_then(|n| get_first_child(n.as_tag()?, parser)) { + let node = tag.children().top()[0].get(parser).unwrap(); + bail!(EhError::Error(node.inner_text(parser).to_string())); + } + dom.get_element_by_id("gdt") .and_then(|n| n.get(parser)?.children()) .context("Failed to find gdt")?