From 8770726f63c93b1ef80f15a22a5f5fa662630988 Mon Sep 17 00:00:00 2001 From: nemanjaASE <93867316+nemanjaASE@users.noreply.github.com> Date: Sun, 16 Mar 2025 16:44:08 +0100 Subject: [PATCH] Add error handling in main.js (verifyIntegration) --- agentic_security/static/main.js | 56 ++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/agentic_security/static/main.js b/agentic_security/static/main.js index c1bc2812..22f43ef0 100644 --- a/agentic_security/static/main.js +++ b/agentic_security/static/main.js @@ -214,33 +214,39 @@ var app = new Vue({ spec: this.modelSpec, }; let startTime = performance.now(); // Capture start time - const response = await fetch(`${SELF_URL}/verify`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(payload), - }); - console.log(response); - let r = await response.json(); - let endTime = performance.now(); // Capture end time - let latency = endTime - startTime; // Calculate latency in milliseconds - latency = latency.toFixed(3) / 1000; // Round to 2 decimal places - this.latency = latency; - if (!response.ok) { - this.updateStatusDot(false); - this.errorMsg = 'Integration verification failed:' + JSON.stringify(r); - this.showToast('Integration verification failed', 'error'); - } else { - this.errorMsg = ''; - this.updateStatusDot(true); - this.okMsg = 'Integration verified'; - this.showToast('Integration verified successfully', 'success'); - this.integrationVerified = true; - // console.log('Integration verified', this.integrationVerified); - // this.$forceUpdate(); + + try { + const response = await fetch(`${SELF_URL}/verify`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }); + + let r = await response.json(); + let endTime = performance.now(); // Capture end time + let latency = ((endTime - startTime) / 1000).toFixed(3); // Calculate latency in milliseconds + this.latency = latency; + + if (!response.ok) { + this.updateStatusDot(false); + this.errorMsg = 'Integration verification failed:' + JSON.stringify(r); + this.showToast('Integration verification failed', 'error'); + } else { + this.errorMsg = ''; + this.updateStatusDot(true); + this.okMsg = 'Integration verified'; + this.showToast('Integration verified successfully', 'success'); + this.integrationVerified = true; + } + } catch (error) { + this.updateStatusDot(true); + this.errorMsg = 'Server unreachable'; + this.showToast('Network error', 'error'); } + this.saveStateToLocalStorage(); }, loadConfigs: async function () {