From c3e9b6ca28c3d029a24efdf1462431eb42c64b5b Mon Sep 17 00:00:00 2001 From: Javier Llamas Ramirez Date: Fri, 10 Sep 2021 16:21:39 -0500 Subject: [PATCH] Decoupling error handling for Document Creation Fixes AuthorizeNet/sdk-python#148 --- authorizenet/apicontrollersbase.py | 9 +++++++-- setup.cfg | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index bab6e0f..beea36c 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -143,13 +143,18 @@ def execute(self): self._httpResponse = self._httpResponse.text[3:] #strip BOM self.afterexecute() try: - self._response = apicontractsv1.CreateFromDocument(self._httpResponse) + self._response = apicontractsv1.CreateFromDocument(self._httpResponse) + except (pyxb.exceptions_.PyXBException, pyxb.exceptions_.PyXBError) as e: + error_details = e.details() + raise e( + 'Validation Error Creating Document: At %s, with Arguments: %s, details:', + type(e), e.args, str(error_details)) + try: #objectify code xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype()) xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'') xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'') self._mainObject = objectify.fromstring(xmlResponse) - except Exception as objectifyexception: anetLogger.error( 'Create Document Exception: %s, %s', type(objectifyexception), objectifyexception.args ) responseString = self._httpResponse diff --git a/setup.cfg b/setup.cfg index 68ebb3d..2e3bd6f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,9 @@ [metadata] -description-file = DESCRIPTION.rst \ No newline at end of file +description-file = DESCRIPTION.rst +[flake8] +max-line-length = 120 +exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules + +[pycodestyle] +max-line-length = 120 +exclude=.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules