diff --git a/main.py b/main.py index ee6fee4..31fc79a 100755 --- a/main.py +++ b/main.py @@ -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", {}) diff --git a/tests/test_category_search.py b/tests/test_category_search.py index 8a22e1f..6a6072a 100644 --- a/tests/test_category_search.py +++ b/tests/test_category_search.py @@ -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