Skip to content

Commit 8549aee

Browse files
authored
Merge pull request #187 from nemanjaASE/issue-173-no-error-handling
Add error handling in main.js (verifyIntegration)
2 parents 414ee62 + 8770726 commit 8549aee

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

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

0 commit comments

Comments
 (0)