-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: Add extensive loggers #29
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
""" | ||
API Base class with util functions | ||
""" | ||
import logging | ||
import json | ||
from typing import List, Dict, Generator | ||
|
||
|
@@ -9,6 +10,7 @@ | |
from ..exceptions import WrongParamsError, InvalidTokenError, QuickbooksOnlineSDKError, \ | ||
NoPrivilegeError, NotFoundItemError, ExpiredTokenError, InternalServerError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class ApiBase: | ||
"""The base class for all API classes.""" | ||
|
@@ -54,6 +56,7 @@ def _query_get_all(self, object_type: str, url: str) -> List[Dict]: | |
response = requests.get(url=request_url.format(start_position), headers=api_headers) | ||
|
||
if response.status_code == 200: | ||
logger.debug('Response for get request for url: %s, %s', url, response.text) | ||
data = json.loads(response.text) | ||
query_response = data['QueryResponse'] | ||
|
||
|
@@ -66,6 +69,7 @@ def _query_get_all(self, object_type: str, url: str) -> List[Dict]: | |
query_response = data['QueryResponse'] | ||
return objects | ||
|
||
logger.info('Response for get request for url: %s, %s', url, response.text) | ||
if response.status_code == 400: | ||
raise WrongParamsError('Some of the parameters are wrong', response.text) | ||
|
||
|
@@ -113,11 +117,14 @@ def _query_get_all_generator(self, object_type: str, url: str) -> Generator[Dict | |
if not query_response or object_type not in query_response: | ||
break | ||
|
||
logger.debug('Response for get request for url: %s, %s', url, response.text) | ||
|
||
yield query_response[object_type] | ||
|
||
start_position += 1000 | ||
|
||
except requests.exceptions.HTTPError as err: | ||
logger.info('Response for get request for url: %s, %s', url, err.response.text) | ||
if err.response.status_code == 400: | ||
raise WrongParamsError('Some of the parameters are wrong', err.response.text) | ||
|
||
|
@@ -153,9 +160,11 @@ def _query(self, url: str) -> List[Dict]: | |
response = requests.get(url=request_url, headers=api_headers) | ||
|
||
if response.status_code == 200: | ||
logger.debug('Response for get request for url: %s, %s', url, response.text) | ||
data = json.loads(response.text) | ||
return data['QueryResponse'] | ||
|
||
logger.info('Response for get request for url: %s, %s', url, response.text) | ||
if response.status_code == 400: | ||
raise WrongParamsError('Some of the parameters are wrong', response.text) | ||
|
||
|
@@ -197,9 +206,11 @@ def _get_request(self, object_type: str, api_url: str) -> List[Dict] or Dict: | |
) | ||
|
||
if response.status_code == 200: | ||
logger.debug('Response for get request for url: %s, %s', api_url, response.text) | ||
result = json.loads(response.text) | ||
return result[object_type] | ||
|
||
logger.info('Response for get request for url: %s, %s', api_url, response.text) | ||
if response.status_code == 400: | ||
raise WrongParamsError('Some of the parameters are wrong', response.text) | ||
|
||
|
@@ -244,8 +255,12 @@ def _post_request(self, data, api_url): | |
) | ||
|
||
if response.status_code == 200: | ||
logger.debug('Response for post request: %s', response.text) | ||
result = json.loads(response.text) | ||
return result | ||
|
||
logger.debug('Payload for post request: %s', data) | ||
logger.info('Response for post request: %s', response.text) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's do logger.info for all non 2xx status code logger.debug you can move it to 2xx block |
||
if response.status_code == 400: | ||
raise WrongParamsError('Some of the parameters are wrong', response.text) | ||
|
@@ -292,9 +307,14 @@ def _post_file(self, data, api_url): | |
) | ||
|
||
if response.status_code == 200: | ||
logger.debug('Response for post request: %s', response.text) | ||
result = json.loads(response.text) | ||
return result['AttachableResponse'][0]['Attachable'] | ||
|
||
|
||
logger.debug('Payload for post request: %s', data) | ||
logger.info('Response for post request: %s', response.text) | ||
|
||
if response.status_code == 400: | ||
raise WrongParamsError('Some of the parameters are wrong', response.text) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be before 257 block, we don't end up reaching here since we're returning at 260