Skip to content

IonQ: Include json body of error response when possible #5349

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

Merged
merged 15 commits into from
Jun 6, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cirq-ionq/cirq_ionq/ionq_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,17 @@ def _make_request(
'IonQ could not find requested resource.'
)
if not _is_retriable(response.status_code):
error = {}
try:
error = response.json()
except json.decoder.JSONDecodeError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will reference json from the parameter. Probably best solution is to import json.decoder as jd or something like that and then us that reference here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ha, right! Thanks for catching

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about this more, I probably shouldn't coverage ignore the except case if I already did a bug

pass # Ignore invalid/missing JSON.
raise ionq_exceptions.IonQException(
'Non-retry-able error making request to IonQ API. '
f'Request Body: {json} '
f'Response Body: {error} '
f'Status: {response.status_code} '
f'Error :{response.reason}',
f'Error:{response.reason}',
response.status_code,
)
message = response.reason
Expand Down