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_wrapperto build messages fromHTTPStatus.phrase, wrapparse_json_payloadintry/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 |
src/telegram/request/_baserequest.py:355
- [nitpick] The variable name
exceptionshadows the built-inexceptionconcept. Consider renaming it to something likeerrortelegram_errorfor 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: