Bibo-Joshi · GitHub

@Bibo-Joshi

@Bibo-Joshi

@Bibo-Joshi

Pull Request Overview

This PR enhances network error handling by using HTTPStatus.phrase for more descriptive messages and chaining JSON parsing errors to provide context.

  • Improved test coverage to validate new error messages and parsing failure behavior
  • Updated _request_wrapper to build messages from HTTPStatus.phrase, wrap parse_json_payload in try/except, and chain exceptions
  • Added changelog entry for the feature

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/request/test_request.py Adjusted tests to check for descriptive HTTP status phrases and JSON parse errors
src/telegram/request/_baserequest.py Enhanced error message construction, used HTTPStatus phrases, and chained parsing exceptions
changes/unreleased/4822.DrW3tJ3KoB8kTmHtNnNEpQ.toml Added changelog entry for this PR
Comments suppressed due to low confidence (2)

src/telegram/request/_baserequest.py:355

  • [nitpick] The variable name exception shadows the built-in exception concept. Consider renaming it to something like err or telegram_error for clarity.
exception: TelegramError = Forbidden(message)

src/telegram/request/_baserequest.py:318

  • [nitpick] Python 3.12 introduces HTTPStatus.is_success, which can replace the manual range check for success codes to make the intent clearer and the code more maintainable.
if HTTPStatus.OK <= code <= 299:

harshil21

@Bibo-Joshi

harshil21

@Bibo-Joshi

@Bibo-Joshi

Read the original on github.com ↗