Skip to content

Commit 8770726

Browse files
committed
Add error handling in main.js (verifyIntegration)
1 parent e171f02 commit 8770726

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

agentic_security/static/main.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -214,33 +214,39 @@ var app = new Vue({
214214
spec: this.modelSpec,
215215
};
216216
let startTime = performance.now(); // Capture start time
217-
const response = await fetch(`${SELF_URL}/verify`, {
218-
method: 'POST',
219-
headers: {
220-
'Content-Type': 'application/json',
221-
},
222-
body: JSON.stringify(payload),
223-
});
224-
console.log(response);
225-
let r = await response.json();
226-
let endTime = performance.now(); // Capture end time
227-
let latency = endTime - startTime; // Calculate latency in milliseconds
228-
latency = latency.toFixed(3) / 1000; // Round to 2 decimal places
229-
this.latency = latency;
230-
if (!response.ok) {
231-
this.updateStatusDot(false);
232-
this.errorMsg = 'Integration verification failed:' + JSON.stringify(r);
233-
this.showToast('Integration verification failed', 'error');
234-
} else {
235-
this.errorMsg = '';
236-
this.updateStatusDot(true);
237-
this.okMsg = 'Integration verified';
238-
this.showToast('Integration verified successfully', 'success');
239-
this.integrationVerified = true;
240-
// console.log('Integration verified', this.integrationVerified);
241-
// this.$forceUpdate();
217+
218+
try {
219+
const response = await fetch(`${SELF_URL}/verify`, {
220+
method: 'POST',
221+
headers: {
222+
'Content-Type': 'application/json',
223+
},
224+
body: JSON.stringify(payload),
225+
});
226+
227+
let r = await response.json();
242228

229+
let endTime = performance.now(); // Capture end time
230+
let latency = ((endTime - startTime) / 1000).toFixed(3); // Calculate latency in milliseconds
231+
this.latency = latency;
232+
233+
if (!response.ok) {
234+
this.updateStatusDot(false);
235+
this.errorMsg = 'Integration verification failed:' + JSON.stringify(r);
236+
this.showToast('Integration verification failed', 'error');
237+
} else {
238+
this.errorMsg = '';
239+
this.updateStatusDot(true);
240+
this.okMsg = 'Integration verified';
241+
this.showToast('Integration verified successfully', 'success');
242+
this.integrationVerified = true;
243+
}
244+
} catch (error) {
245+
this.updateStatusDot(true);
246+
this.errorMsg = 'Server unreachable';
247+
this.showToast('Network error', 'error');
243248
}
249+
244250
this.saveStateToLocalStorage();
245251
},
246252
loadConfigs: async function () {

0 commit comments

Comments
 (0)