Skip to content

Commit

Permalink
feat: Added Extensive Loggers (#95)
Browse files Browse the repository at this point in the history
* feat: Added Extensive Loggers

* better logging

* comment resolved

* bump version

* comment resolved

* removed level
  • Loading branch information
Ashutosh619-sudo authored Oct 14, 2024
1 parent 8ebebf0 commit 4750c1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions sageintacctsdk/apis/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
API Base class with util functions
"""
import json
import logging
import datetime
import uuid
from warnings import warn
Expand All @@ -17,6 +18,8 @@
from .constants import dimensions_fields_mapping


logger = logging.getLogger(__name__)

class ApiBase:
"""The base class for all API classes."""

Expand Down Expand Up @@ -186,6 +189,7 @@ def __post_request(self, dict_body: dict, api_url: str):
A response from the request (dict).
"""

logger.debug('Payload for post request: %s', dict_body)
raw_response = self.__post_request_for_raw_response(dict_body, api_url)
try:
parsed_xml = xmltodict.parse(raw_response.text, force_list={self.__dimension})
Expand All @@ -196,6 +200,17 @@ def __post_request(self, dict_body: dict, api_url: str):
parsed_response = json.loads(json.dumps(parsed_xml))

if raw_response.status_code == 200:
response = parsed_response.get('response', {})
control_status = response.get('control', {}).get('status', '')
auth_status = response.get('operation', {}).get('authentication', {}).get('status', '')
result_status = response.get('operation', {}).get('result', {}).get('status', '')


if control_status == 'failure' or auth_status == 'failure' or result_status == 'failure':
logger.info('Response for post request: %s', raw_response.text)
else:
logger.debug('Response for post request: %s', raw_response.text)

if parsed_response['response']['control']['status'] == 'success':
api_response = parsed_response['response']['operation']

Expand Down Expand Up @@ -235,6 +250,8 @@ def __post_request(self, dict_body: dict, api_url: str):
}
raise WrongParamsError('Something went wrong', custom_response)


logger.info('Response for post request: %s', raw_response.text)
if 'result' in parsed_response:
if 'errormessage' in parsed_response['result']:
parsed_response = parsed_response['result']['errormessage']
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='sageintacctsdk',
version='1.23.2',
version='1.23.3',
author='Ashwin T',
author_email='[email protected]',
description='Python SDK for accessing Sage Intacct APIs',
Expand Down

0 comments on commit 4750c1f

Please sign in to comment.