Harden OAuthRefreshException with robust parsing, clearer formatting, and unit tests#104
Draft
Copilot wants to merge 4 commits into
Draft
Harden OAuthRefreshException with robust parsing, clearer formatting, and unit tests#104Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
Copilot
AI
changed the title
[WIP] Refactor OAuthRefreshException and add unit tests
Extract OAuthRefreshException hardening from PR #102 (commit a5e1448) with focused unit coverage
May 28, 2026
- Add class docstring and message attribute - Expand constructor to accept error, error_description, and cause - Add _load_data() helper that safely parses response JSON (handles missing response, missing .json(), invalid JSON, non-dict payloads) - Populate _error and _error_description from explicit args first, falling back to parsed response data - Implement __str__ with full, error-only, and fallback formatting
Cover: - default str form when no response/error details are present - parsing error and error_description from response JSON payload - explicit constructor args overriding parsed response data - graceful behavior when response is None or .json() raises - str formatting for error-only and error+description cases - cause attribute preservation
Copilot
AI
changed the title
Extract OAuthRefreshException hardening from PR #102 (commit a5e1448) with focused unit coverage
Harden OAuthRefreshException with robust parsing, clearer formatting, and unit tests
May 28, 2026
This was referenced May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OAuthRefreshException.__init__unconditionally calledself.response.json(), crashing onNoneresponse, missing.json(), or non-JSON payloads — common in real error paths.trakt/errors.pymessage = 'Unauthorized - OAuth token refresh failed'(response, error, error_description, cause)— explicit args take precedence over parsed response data_load_data()safely parses response JSON, returning{}on missing response,AttributeError,ValueError, orJSONDecodeError__str__rendersmessage: error - description,message: error, ormessagedepending on available fieldstests/test_errors.pyNoneresponse,.json()raising, error-only str, andcausepreservationOriginal prompt
This pull request was created from Copilot chat.