From af2eac4334a4ccfbb428d88dce978ba6cfd4ae8a Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Tue, 17 Sep 2019 15:53:23 +0530 Subject: [PATCH] fix: Create error log if something goes wrong while call log creation (#19055) * fix: Create error log if something goes wrong while call log creation - For better debbugging * fix: Rollback if any error occurs during call log creation --- .../exotel_integration.py | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/erpnext/erpnext_integrations/exotel_integration.py b/erpnext/erpnext_integrations/exotel_integration.py index 09c399e6aaf..167fcb71652 100644 --- a/erpnext/erpnext_integrations/exotel_integration.py +++ b/erpnext/erpnext_integrations/exotel_integration.py @@ -1,5 +1,6 @@ import frappe import requests +from frappe import _ # api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call # api/method/erpnext.erpnext_integrations.exotel_integration.handle_end_call @@ -7,19 +8,24 @@ import requests @frappe.whitelist(allow_guest=True) def handle_incoming_call(**kwargs): - exotel_settings = get_exotel_settings() - if not exotel_settings.enabled: return + try: + exotel_settings = get_exotel_settings() + if not exotel_settings.enabled: return - call_payload = kwargs - status = call_payload.get('Status') - if status == 'free': - return + call_payload = kwargs + status = call_payload.get('Status') + if status == 'free': + return - call_log = get_call_log(call_payload) - if not call_log: - create_call_log(call_payload) - else: - update_call_log(call_payload, call_log=call_log) + call_log = get_call_log(call_payload) + if not call_log: + create_call_log(call_payload) + else: + update_call_log(call_payload, call_log=call_log) + except Exception as e: + frappe.db.rollback() + frappe.log_error(title=_('Error in Exotel incoming call')) + frappe.db.commit() @frappe.whitelist(allow_guest=True) def handle_end_call(**kwargs): @@ -101,4 +107,4 @@ def get_exotel_endpoint(action): api_token=settings.api_token, sid=settings.account_sid, action=action - ) \ No newline at end of file + )