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

VR-7747 change client to only show "message" field from http error response if it has one #1650

Merged
merged 6 commits into from
Nov 13, 2020

Conversation

nhatsmrt
Copy link
Contributor

@nhatsmrt nhatsmrt commented Nov 12, 2020

Error msg is now:

429 Client Error: LIMIT_RUN_NUMBER: “Number of experiment runs exceeded”: Your trial account allows you to log upto 10 experiment runs. Try deleting prior experiment runs in order to proceed. for url: <url> at 2020-11-12 19:00:31.865000 UTC

(I removed the url for privacy reasons).
Basically re-introduce the logic changed in #1083, with some slight modifications.

@nhatsmrt
Copy link
Contributor Author

cc @conradoverta this is what you want right?

@@ -528,7 +528,12 @@ def raise_for_http_error(response):
curr_time = timestamp_to_str(now(), utc=True)
time_str = " at {} UTC".format(curr_time)

reason = six.ensure_str(response.text.strip())
try:
reason = six.ensure_str(body_to_json(response)['message'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to call ensure str, otherwise would get 'ascii' codec can't encode character u'\u201c' in position 18: ordinal not in range(128) error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, did you test this in Python 2? (Could you try it out in both 2 and 3, if you can?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tried for both. LGTM.

Copy link
Contributor

@convoliution convoliution left a comment

Choose a reason for hiding this comment

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

Looks good to me

try:
reason = body_to_json(response)['message']
except (ValueError, # not JSON response
TypeError, # body_to_json return a single string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@convoliution apparently body_to_json could return a string 🤷Specifically, response.json() returns LIMIT_ENDPOINT_NUMBER: currently at maximum number of endpoints when we try to create a second endpoint 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that complicates things.
In that case, could you do me a favor and split this try-except into multiple checks?
It was already a shaky idea when I tried catching two error types simultaneously—trying to catch 3 is really prone to issues down the line

Something like (pseudocode)

try:
    reason = body_to_json()
except ValueError:
    raise

if reason is dict and 'message' in reason:
    reason['message']

# etc...

Copy link
Contributor Author

@nhatsmrt nhatsmrt Nov 13, 2020

Choose a reason for hiding this comment

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

Fixed. See latest commits

Copy link
Contributor

@convoliution convoliution left a comment

Choose a reason for hiding this comment

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

See comment

Copy link
Contributor

@convoliution convoliution left a comment

Choose a reason for hiding this comment

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

Makes sense to me! Thanks ✨

@nhatsmrt
Copy link
Contributor Author

🚢

@nhatsmrt nhatsmrt merged commit e1d856b into master Nov 13, 2020
@nhatsmrt nhatsmrt deleted the use-message-field-only branch November 13, 2020 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants