From 508f7d4cc1f2ea7803b3dc45d6a3f989ecdfd043 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Wed, 10 Jul 2024 09:57:11 +0300 Subject: [PATCH] v7.3.2.0: Refactor javascript code and update error handling in API This commit includes two major changes. Javascript code in udp.js has been refactored to fix the sequence of operations. We have moved the getScript function inside the bracket to ensure smoother operation. Also, error handling in api_funct.py has been simplified and made more consistent by passing json.loads instead of raw strings to install_service method, and by directly setting 'e' as a value in case of exceptions. A minor style change has also been added on ha_cluster.html. --- api/api_funct.py | 12 ++++++------ app/static/js/udp.js | 2 +- app/templates/ha_cluster.html | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/api_funct.py b/api/api_funct.py index 67e5b7fe..3ab8f6bb 100644 --- a/api/api_funct.py +++ b/api/api_funct.py @@ -862,25 +862,25 @@ def create_ha_cluster(): try: json_loads['cluster_id'] = cluster_id json_dump = json.dumps(json_loads) - service_mod.install_service('keepalived', json_dump) + service_mod.install_service('keepalived', json.loads(json_dump)) except Exception as e: - data['status'].setdefault('keepalived', f'error: {e}') + data['status'].setdefault('keepalived', f'{e}') else: data['status'].setdefault('keepalived', 'done') if json_loads['services']['haproxy']['enabled']: try: - service_mod.install_service('haproxy', body) + service_mod.install_service('haproxy', json.loads(body)) except Exception as e: - data['status'].setdefault('haproxy', f'error: {e}') + data['status'].setdefault('haproxy', f'{e}') else: data['status'].setdefault('haproxy', 'done') if json_loads['services']['nginx']['enabled']: try: - service_mod.install_service('nginx', body) + service_mod.install_service('nginx', json.loads(body)) except Exception as e: - data['status'].setdefault('nginx', f'error: {e}') + data['status'].setdefault('nginx', f'{e}') else: data['status'].setdefault('nginx', 'done') diff --git a/app/static/js/udp.js b/app/static/js/udp.js index 8790fefb..3610a273 100644 --- a/app/static/js/udp.js +++ b/app/static/js/udp.js @@ -346,10 +346,10 @@ function getUDPListener(listener_id, new_listener=false) { $('#listener-' + listener_id).replaceWith(data); } $('#listener-'+listener_id).removeClass('animated-background'); + $.getScript(awesome); } } }); - $.getScript(awesome); } function confirmDeleteListener(listener_id) { $("#dialog-confirm").dialog({ diff --git a/app/templates/ha_cluster.html b/app/templates/ha_cluster.html index 7fb74d70..de83ca29 100644 --- a/app/templates/ha_cluster.html +++ b/app/templates/ha_cluster.html @@ -110,7 +110,7 @@ - + {{ lang.ha_page.use_src }}