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

Error handling #62

Merged

Conversation

elkezza
Copy link
Contributor

@elkezza elkezza commented May 24, 2024

Adding exception handling, by introducing ExoscaleAPIException as base class for all exoscale exceptions,ExoscaleAPIClientException for handling client-side errors 4xx and ExoscaleAPIServerException for server-side errors 5xx.

Tested them locally and works as expected.

…ase class for all exoscale exceptions,`ExoscaleAPIClientException` for handling client-side errors 4xx and `ExoscaleAPIServerException` for server-side errors 5xx.
@elkezza elkezza requested a review from brutasse May 24, 2024 15:53
@brutasse
Copy link
Member

Fixes #61

Copy link
Member

@brutasse brutasse left a comment

Choose a reason for hiding this comment

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

Thanks @elkezza. This looks good but it would be useful to have some basic tests:

  • mock the HTTP library to simulate HTTP error codes
  • make API requests and ensure they raise the appropriate exceptions

This can be done in tests/test_client.py. Thanks 👍

exoscale/api/v2.py Show resolved Hide resolved
@elkezza
Copy link
Contributor Author

elkezza commented May 27, 2024

@brutasse thank you for your feedback, I will do accordingly.

@elkezza elkezza requested a review from brutasse May 27, 2024 13:39

# Mock a 500 server error
requests_mock.get(
"https://api-ch-gva-2.exoscale.com/v2/500_error",
Copy link
Member

Choose a reason for hiding this comment

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

Can you simulate a proper API operation raising a 500? This custom path means you have to resort to using client.session below which isn't part of the documented interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find any use-case to trigger 5xx error, however in the new commit I tried to mock use-case where the end point is disabled.
Please let me know if any change needed.

@elkezza elkezza requested a review from brutasse May 27, 2024 19:38
Comment on lines 69 to 70
except Exception as e:
assert "503 Server Error" in str(e)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
except Exception as e:
assert "503 Server Error" in str(e)

Not sure why this would be necessary - other than that the adjustment looks good 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is redundant, good catch, thank you : ).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brutasse after your green light, is more reviewer required, to merge the branch?

@elkezza elkezza requested a review from brutasse May 28, 2024 09:35
Copy link
Member

@brutasse brutasse left a comment

Choose a reason for hiding this comment

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

👍 LGTM, you can merge after the final suggested change @elkezza. Thanks!

exoscale/api/exceptions.py Outdated Show resolved Hide resolved
@elkezza
Copy link
Contributor Author

elkezza commented May 28, 2024

👍 LGTM, you can merge after the final suggested change @elkezza. Thanks!

@elkezza elkezza closed this May 28, 2024
@elkezza elkezza reopened this May 28, 2024
@elkezza
Copy link
Contributor Author

elkezza commented May 28, 2024

👍 LGTM, you can merge after the final suggested change @elkezza. Thanks!

ack, thanks!

@elkezza elkezza merged commit 77c44dc into master May 28, 2024
7 checks passed
@elkezza elkezza deleted the salehelkaza/sc-95846/gh-issue-python-exoscale-implement-proper branch May 28, 2024 10:08
Copy link
Member

@pierre-emmanuelJ pierre-emmanuelJ left a comment

Choose a reason for hiding this comment

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

LGTM thanks 👍

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