From d897ba3fac8a32257825400e6cf8ae13d5e6f657 Mon Sep 17 00:00:00 2001 From: Ashwin Thanaraj <37061471+ashwin1111@users.noreply.github.com> Date: Tue, 3 Jan 2023 20:14:22 +0530 Subject: [PATCH] Handle token expire exceptions during payments sync (#197) --- apps/xero/tasks.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/apps/xero/tasks.py b/apps/xero/tasks.py index 417bc046..bb910e79 100644 --- a/apps/xero/tasks.py +++ b/apps/xero/tasks.py @@ -935,6 +935,33 @@ def create_payment(workspace_id): task_log.save() + except NoPrivilegeError as exception: + xero_credentials = XeroCredentials.objects.filter(workspace_id=workspace_id).first() + xero_credentials.refresh_token = None + xero_credentials.country = None + xero_credentials.is_expired = True + xero_credentials.save() + logger.error(exception.message) + task_log.status = 'FAILED' + task_log.detail = None + task_log.xero_errors = [ + { + 'error': { + 'Elements': [ + { + 'ValidationErrors': [ + { + 'Message': 'Xero account got disconnected, please go Configurations -> Tenant page and connect to Xero again' + } + ] + } + ] + } + } + ] + + task_log.save() + except Exception: error = traceback.format_exc() task_log.detail = {