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

feat: Add extensive loggers #29

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion qbosdk/apis/api_base.py
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

Expand All @@ -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."""
Expand Down Expand Up @@ -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']

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Copy link
Contributor

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

logger.info('Response for post request: %s', response.text)

Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='qbosdk',
version='0.18.0',
version='0.18.1',
author='Shwetabh Kumar',
author_email='shwetabh.kumar@fyle.in',
description='Python SDK for accessing Quickbooks Online APIs',
Expand Down