Skip to content

feat: Handle situations when server is not returning JSON response - #417

Merged
martin-majlis merged 4 commits into
masterfrom
2026-03-02-make-fetching-data-more-robust
Mar 2, 2026
Merged

martin-majlis merged 4 commits into
masterfrom
2026-03-02-make-fetching-data-more-robust

Conversation

@martin-majlis

@martin-majlis martin-majlis commented Mar 2, 2026 •

Copy link
Copy Markdown
Owner

Improve error handling, retry logic, and exception naming

Builds on the existing JSON error handling to add full retry support, consistent exception naming, and reduced complexity in _query.

Exception renaming

All exceptions prefixed with Wiki to avoid shadowing Python built-ins (PYL-W0622): WikiHttpError, WikiRateLimitError, WikiHttpTimeoutError, WikiInvalidJsonError, WikiConnectionError.

Retry logic

_query previously made a single unguarded request. It now retries transient errors (429, 5xx, timeouts, connection errors) with exponential backoff, honours Retry-After, and raises immediately for non-retryable errors. Controlled by new Wikipedia(max_retries=3, retry_wait=1.0) constructor parameters.

_query refactor

Cyclomatic complexity reduced from 18 to low by extracting two helpers: _attempt_request (one HTTP GET, converts requests exceptions) and _handle_response (status code dispatch). _query is now a thin retry loop.

Also

  • API.rst / README.rst updated with new exception names and retry docs
  • Docstrings on all public Wikipedia methods updated with :raises: entries
  • tests/query_errors_test.py added covering all error paths, retry behaviour, and exception hierarchy

@martin-majlis martin-majlis changed the title feat: Make fetching feat: Handle situations when server is not returning JSON response Mar 2, 2026
@martin-majlis
martin-majlis marked this pull request as ready for review March 2, 2026 20:18
@martin-majlis
martin-majlis merged commit 7a67842 into master Mar 2, 2026
33 of 34 checks passed
@martin-majlis
martin-majlis deleted the 2026-03-02-make-fetching-data-more-robust branch March 2, 2026 20:18
@codecov

codecov Bot commented Mar 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.01%. Comparing base (1bdb2d9) to head (b6f6357).
⚠️ Report is 165 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #417      +/-   ##
==========================================
+ Coverage   66.03%   70.01%   +3.98%     
==========================================
  Files           2        2              
  Lines         630      697      +67     
==========================================
+ Hits          416      488      +72     
+ Misses        214      209       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant