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

Add API exception #113

Merged

Conversation

malkin0xb8
Copy link
Collaborator

Added the API exception alongside cleaned up a few area that have been made redundant

This allows for more descriptive error handling when a request exception occurs

Previous:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.api.com/api/v2/users/call-center?userId=userID@userID.com

New:

odins_spear.exceptions.OSApiResponseError: ODIN API Error 400: [Error 4410] Service is not assigned to this subscriber: Call Center - Basic

Added the API exception alongside cleaned up a few area that have been made redundant
@malkin0xb8 malkin0xb8 linked an issue Sep 10, 2024 that may be closed by this pull request
@malkin0xb8 malkin0xb8 added the enhancement New feature or request label Sep 10, 2024
@@ -1,5 +1,6 @@
import requests
import json
from . import exceptions
Copy link
Owner

Choose a reason for hiding this comment

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

Change to ' from .exceptions import OSAPIResponseError

When importing its good to keep them as light as possible getting only what you need.

Copy link
Owner

@Jordan-Prescott Jordan-Prescott left a comment

Choose a reason for hiding this comment

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

Just a few bits to touch up.

try:
response.raise_for_status()
except requests.exceptions.RequestException:
raise exceptions.OSApiResponseError(response)
Copy link
Owner

Choose a reason for hiding this comment

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

Adjust inline with first comment.

@@ -92,6 +93,12 @@ def _rate_limited_request(self, method, endpoint, data=None, params=None):
self.logger._log_request(endpoint=endpoint, response_code=response.status_code)

# flags errors if any returned from the API
response.raise_for_status()
return response.json()
try:
Copy link
Owner

Choose a reason for hiding this comment

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

Add this to the the _request method. Its only applied to the rate limited version.

Copy link
Owner

@Jordan-Prescott Jordan-Prescott left a comment

Choose a reason for hiding this comment

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

Resolved comments

@Jordan-Prescott Jordan-Prescott merged commit 149dc13 into main Sep 17, 2024
@Jordan-Prescott Jordan-Prescott deleted the 111-add-an-api-exception-which-passes-through-odin-errors branch September 17, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

Add an API Exception which passes through Odin Errors
2 participants