diff --git a/sageintacctsdk/apis/api_base.py b/sageintacctsdk/apis/api_base.py index 6987d25..5b2c47c 100644 --- a/sageintacctsdk/apis/api_base.py +++ b/sageintacctsdk/apis/api_base.py @@ -2,6 +2,7 @@ API Base class with util functions """ import json +import logging import datetime import uuid from warnings import warn @@ -17,6 +18,8 @@ from .constants import dimensions_fields_mapping +logger = logging.getLogger(__name__) + class ApiBase: """The base class for all API classes.""" @@ -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}) @@ -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'] @@ -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'] diff --git a/setup.py b/setup.py index 1001f12..eb3e944 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='sageintacctsdk', - version='1.23.2', + version='1.23.3', author='Ashwin T', author_email='ashwin.t@fyle.in', description='Python SDK for accessing Sage Intacct APIs',