summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/hircine/plugins/scrapers/ehentai_api.py2
-rw-r--r--tests/plugins/scrapers/test_ehentai_api.py16
2 files changed, 18 insertions, 0 deletions
diff --git a/src/hircine/plugins/scrapers/ehentai_api.py b/src/hircine/plugins/scrapers/ehentai_api.py
index d9d539d..d276c5b 100644
--- a/src/hircine/plugins/scrapers/ehentai_api.py
+++ b/src/hircine/plugins/scrapers/ehentai_api.py
@@ -71,5 +71,7 @@ class EHentaiAPIScraper(Scraper):
yield from handler.scrape(response)
except json.JSONDecodeError as err:
raise ScrapeError("Could not parse JSON response") from err
+ except (KeyError, IndexError) as err:
+ raise ScrapeError("Response is missing 'gmetadata' field") from err
else:
raise ScrapeError(f"Request failed with status code {request.status_code}")
diff --git a/tests/plugins/scrapers/test_ehentai_api.py b/tests/plugins/scrapers/test_ehentai_api.py
index dd283e1..c746440 100644
--- a/tests/plugins/scrapers/test_ehentai_api.py
+++ b/tests/plugins/scrapers/test_ehentai_api.py
@@ -124,6 +124,22 @@ def test_raises_scrape_error_with_invalid_json(requests_mock, gen_comic):
assert set(scraper.collect()) == set()
+def test_raises_scrape_error_with_missing_field(requests_mock, gen_comic):
+ comic = next(gen_comic)
+ comic.url = "https://exhentai.org/g/1025913/fdaabef1a2"
+
+ scraper = ehentai_api.EHentaiAPIScraper(comic)
+
+ requests_mock.post(ehentai_api.API_URL, text="{}")
+
+ assert scraper.is_available
+ assert scraper.id == 1025913
+ assert scraper.token == "fdaabef1a2"
+
+ with pytest.raises(ScrapeError, match="Response is missing 'gmetadata' field"):
+ assert set(scraper.collect()) == set()
+
+
def test_raises_scrape_error_with_error_code(requests_mock, gen_comic):
comic = next(gen_comic)
comic.url = "https://exhentai.org/g/1025913/fdaabef1a2"