From e36d7282a5e44945b8cb92f2347196371a62f7f9 Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Fri, 5 May 2023 12:57:18 +0530 Subject: [PATCH] Netsuite message parse (#382) * Netsuite message parsed * Netsuite message parsed * Netsuite message parsed * Netsuite message parsed * Netsuite message parsed * Comments resolved * Comments resolved * Comments resolved * Comments resolved * Comments resolved * Comments resolved * Comments resolved --- apps/netsuite/connector.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/netsuite/connector.py b/apps/netsuite/connector.py index cc0fd073..77d0b2eb 100644 --- a/apps/netsuite/connector.py +++ b/apps/netsuite/connector.py @@ -62,12 +62,18 @@ def __decode_project_or_customer_name(name): @staticmethod def get_message_and_code(raw_response): - response = eval(raw_response.text) - logger.info('Charge Card Error - %s', response) - code = response['error']['code'] - message = json.loads(response['error']['message'])['message'] - + try: + response = eval(raw_response.text) + logger.info('Charge Card Error - %s', response) + code = response['error']['code'] + message = json.loads(response['error']['message'])['message'] + except Exception: + parsed_response = json.loads((eval(raw_response.text)).replace('"{', '{').replace('}"', '}').replace('\\', '').replace('"https://', "'https://").replace('.html"', ".html'")) + message = parsed_response['error']['message']['message'] + code = parsed_response['error']['code'] return code, message + + @staticmethod def get_tax_code_name(item_id, tax_type, rate): @@ -1300,8 +1306,10 @@ def post_credit_card_charge(self, credit_card_charge: CreditCardCharge, elif configuration.change_accounting_period: logger.info('Charge Card Error - %s', raw_response.text) - - error_message = json.loads(eval(raw_response.text)['error']['message'])['message'] + try: + error_message = json.loads((eval(raw_response.text)))['error']['message']['message'] + except Exception: + error_message = json.loads((eval(raw_response.text)).replace('"{', '{').replace('}"', '}').replace('\\', '').replace('"https://', "'https://").replace('.html"', ".html'"))['error']['message']['message'] if error_message == 'The transaction date you specified is not within the date range of your accounting period.': first_day_of_month = datetime.today().date().replace(day=1) credit_card_charges_payload['tranDate'] = first_day_of_month.strftime('%m/%d/%Y')