From e2372e58b5c0ee64a965922d30ef6e2686d2f1b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 17 Feb 2024 13:44:20 +0100 Subject: [PATCH] refactor(ui): add vue.js error handler MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- ui/web/src/composables/UIClient.ts | 7 +++++-- ui/web/src/main.ts | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index 0ed5d82e..4e7fb249 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -124,6 +124,9 @@ export class UIClient { `${this.configuration.uiServer.secure === true ? ApplicationProtocol.WSS : ApplicationProtocol.WS}://${this.configuration.uiServer.host}:${this.configuration.uiServer.port}`, protocols ) + this.ws.onopen = openEvent => { + console.info('WebSocket opened', openEvent) + } this.ws.onmessage = this.responseHandler.bind(this) this.ws.onerror = errorEvent => { console.error('WebSocket error: ', errorEvent) @@ -146,7 +149,7 @@ export class UIClient { const msg = JSON.stringify([uuid, procedureName, payload]) const sendTimeout = setTimeout(() => { this.responseHandlers.delete(uuid) - return reject(new Error(`Send request '${procedureName}' message timeout`)) + return reject(new Error(`Send request '${procedureName}' message: connection timeout`)) }, 60000) try { this.ws.send(msg) @@ -158,7 +161,7 @@ export class UIClient { clearTimeout(sendTimeout) } } else { - throw new Error(`Send request '${procedureName}' message: connection not opened`) + reject(new Error(`Send request '${procedureName}' message: connection closed`)) } }) } diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index 1b4d7ac6..ac9c9e82 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -8,6 +8,12 @@ const app = createApp(App) fetch('/config.json') .then(response => response.json()) .then(config => { + app.config.errorHandler = (error, instance, info) => { + console.error('Error:', error) + console.info('Vue instance:', instance) + console.info('Error info:', info) + // TODO: Add code for UI notifications or other error handling logic + } app.config.globalProperties.$UIClient = UIClient.getInstance(config) app.use(router).mount('#app') }) -- 2.34.1