Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include response in HTTPError for invalid refresh token #35

Merged
merged 3 commits into from
Oct 26, 2022
Merged

Include response in HTTPError for invalid refresh token #35

merged 3 commits into from
Oct 26, 2022

Conversation

NIR7cd
Copy link
Contributor

@NIR7cd NIR7cd commented Oct 24, 2022

Context:
The requests.exceptions.HTTPError exception has a response attribute which normally stores the response to which that error pertains. When manually creating an instance of requests.exceptions.HTTPError response is an optional argument that one can pass to the constructor in order to populate this attribute. This attribute can be useful to find out more about why the response is considered to be an error. For example, a user may want to do the following:

except HTTPError as e:
    log.error(f"Got error response with status code {e.response.status_code}")

Description of the Change:
This change modifies the error handling in Connection.update_refresh_token to make sure that the requests.exceptions.HTTPError that is raised when the refresh token is invalid has a valid response attribute.

Benefits:
Consumers can check for things like the status code and error message when they catch an HTTPError that XCC threw. This can be useful if consuming code wants to check specifically for an invalid refresh token and have different behavior based on that specific error. It also prevents code that checks for the response from getting an AttributeError when attempting to do so.

Possible Drawbacks:

Related GitHub Issues:

@NIR7cd NIR7cd marked this pull request as ready for review October 24, 2022 14:25
Copy link
Collaborator

@Mandrenkov Mandrenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, @NIR7cd! The change and motivation are quite clear. 👍

I know this sounds pedantic, but do you mind modifying the following test to check that the response object is now included as part of the HTTPError?

TestConnection.test_update_access_token_failure_due_to_invalid_refresh_token()

@NIR7cd
Copy link
Contributor Author

NIR7cd commented Oct 24, 2022

I have updated the TestConnection.test_update_access_token_failure_due_to_invalid_refresh_token() unit test to make sure that the HTTPError has the response attribute, and to make sure that the response attribute matches the expectation for what it should be in the case of invalid refresh token.

Copy link
Collaborator

@Mandrenkov Mandrenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me. 🚢

@Mandrenkov Mandrenkov merged commit da47bb9 into XanaduAI:main Oct 26, 2022
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.

2 participants