Show Wikipedia category API errors

This commit is contained in:
Edward Betts 2026-08-22 22:12:29 +01:00
parent b7ba24b567
commit 15bbbecacf
2 changed files with 11 additions and 6 deletions

View file

@ -463,10 +463,11 @@ def get_articles_without_images(
if articles_without_images:
error = (
"Wikipedia stopped responding before the whole category could "
"be checked. Showing partial results; please try again."
"be checked. Showing partial results. "
f"Wikipedia API error: {e}"
)
else:
error = "Unable to load articles from Wikipedia. Please try again."
error = f"Unable to load articles. Wikipedia API error: {e}"
break
pages = data.get("query", {}).get("pages", {})

View file

@ -12,7 +12,7 @@ def test_api_failure_is_not_reported_as_an_empty_success():
result = get_articles_without_images("Category:Example")
assert result.articles == []
assert result.error == "Unable to load articles from Wikipedia. Please try again."
assert result.error == "Unable to load articles. Wikipedia API error: offline"
def test_api_error_response_is_not_reported_as_an_empty_success():
@ -31,7 +31,10 @@ def test_api_error_response_is_not_reported_as_an_empty_success():
result = get_articles_without_images("Category:Example")
assert result.articles == []
assert result.error == "Unable to load articles from Wikipedia. Please try again."
assert result.error == (
"Unable to load articles. Wikipedia API error: "
"readonly: Wikipedia is read-only"
)
def test_api_failure_after_results_marks_them_as_partial():
@ -63,13 +66,14 @@ def test_api_failure_after_results_marks_them_as_partial():
assert [article.title for article in result.articles] == ["No image"]
assert result.error is not None
assert "partial results" in result.error
assert "offline" in result.error
def test_category_page_does_not_claim_success_after_api_failure():
result = CategoryResult(
articles=[],
gcmcontinue=None,
error="Unable to load articles from Wikipedia. Please try again.",
error="Unable to load articles. Wikipedia API error: test failure",
)
with (
@ -81,5 +85,5 @@ def test_category_page_does_not_claim_success_after_api_failure():
page = response.get_data(as_text=True)
assert response.status_code == 200
assert "Unable to load articles from Wikipedia" in page
assert "Wikipedia API error: test failure" in page
assert "All articles in this category have images" not in page