Skip to content

Implement Error Handling in backend - T415715 Micro-Task#88

Open
Mariam22-hub wants to merge 3 commits intoindictechcom:masterfrom
Mariam22-hub:Wikifile-Transfer-T415715
Open

Implement Error Handling in backend - T415715 Micro-Task#88
Mariam22-hub wants to merge 3 commits intoindictechcom:masterfrom
Mariam22-hub:Wikifile-Transfer-T415715

Conversation

@Mariam22-hub
Copy link
Copy Markdown

@Mariam22-hub Mariam22-hub commented Mar 29, 2026

This PR addresses this backend improvement tasks:

Error Handling & Observability — strengthen exception handling, introduce structured logging, standardise API error responses, and capture async task errors

Key Changes

  • Standardized API Responses

    • Unified response format across all endpoints, by adding generic functions (error_response, success_response) in utils.py
    • Removed inconsistent patterns
  • Request Handling

    • Added input validation and safe JSON parsing (get_json(silent=True))
    • Guarded URL parsing to prevent runtime errors
  • Consistent Error Handling

    • Mapped domain-specific exceptions to appropriate HTTP status codes, e.g:
      • FileNotFoundOnWikiError → 404
      • ImageDownloadError, APIRequestError → 502
    • Clean handling of CSRF and upload-related errors
  • Codebase Refactor

    • Moved duplicated shared logic (e.g. _fetch_csrf_token) to generic functions
  • Structured Logging

    • Replaced ad-hoc logging.basicConfig calls with a centralised logger configuration. All modules now call get_logger(__name__) to get a consistently configured logger.
  • Config File

    • Replaced all os.environ reads and hardcoded settings with a single config.ini file read at import time via Python's built-in configparser.
  • Tests

    • Added comprehensive unit tests, using pytest, to test all flows for each function and api in app.py, utils.py, tasks.py, exceptions.py, and logger.py

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