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

Improve reporting of known API calls error scenarios #211

Merged
merged 3 commits into from
Jan 20, 2025

Conversation

airwoodix
Copy link
Collaborator

@airwoodix airwoodix commented Jan 17, 2025

Summary

Improve the reporting of errors from the remote server (portal or direct-access resource) propagated through HTTP error status codes.

For example, submitting a circuit on a direct-access backend that has less ions loaded than the circuit requires physical qubits is now reported as: (modulo changes in the backend's implementation)

Traceback (most recent call last):
  ...
httpx.HTTPStatusError: Client error '413 Request Entity Too Large' for url 'http://localhost:3001/api/v1/circuit/'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  ...
qiskit_aqt_provider.api_client.errors.APIError: Not enough qubits: available qubits=0, requested=4

Details and comments

The new APIError type is purposely not linked to httpx.HTTPStatusError, such that it can be extended to errors reported by the remote servers with success status codes (dedicated error payloads). For the moment, the interface only assumes that the detail object has an acceptable string representation.

@airwoodix airwoodix marked this pull request as ready for review January 17, 2025 16:25
Copy link
Collaborator

@fg-aqt fg-aqt left a comment

Choose a reason for hiding this comment

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

I would split the test_http_response_raise_for_status in test_errors.py up for easier readability. The test confirming that an APIError is raised should be separate from the one that checks that nothing is raised if the Response has a 2XX code.

@airwoodix airwoodix force-pushed the improve-api-error-reporting branch from a7f0e9c to 8e89097 Compare January 20, 2025 10:34
@airwoodix
Copy link
Collaborator Author

Refactored test_http_response_raise_for_status in 8e89097.

@airwoodix airwoodix requested a review from fg-aqt January 20, 2025 10:46
@airwoodix airwoodix merged commit 1407502 into master Jan 20, 2025
15 checks passed
@airwoodix airwoodix deleted the improve-api-error-reporting branch January 20, 2025 11:32
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.

3 participants