From 97062c98deaa4f91d51d625cc182a1e37ec9169a Mon Sep 17 00:00:00 2001 From: Abdhesh Nayak Date: Thu, 14 Mar 2024 12:13:17 +0530 Subject: [PATCH] Improve/error handling (#143) * :art: Improved error handling for serverside --- web/lib/client/components/logger/index.tsx | 2 +- web/lib/client/helpers/socket/context.tsx | 66 +++++++++++++--------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/web/lib/client/components/logger/index.tsx b/web/lib/client/components/logger/index.tsx index f85dd9a34..bdce1fc41 100644 --- a/web/lib/client/components/logger/index.tsx +++ b/web/lib/client/components/logger/index.tsx @@ -747,7 +747,7 @@ const LogComp = ({ {isLoading && } {errors.length ? ( -
{JSON.stringify(errors)}
+
{JSON.stringify(errors, null, 2)}
) : ( logs.length > 0 && ( { useDebounce( () => { if (typeof window !== 'undefined') { - try { - sockPromise.current = new Promise((res, rej) => { - let rejected = false; - try { - // eslint-disable-next-line new-cap - const w = new wsock.w3cwebsocket(`${socketUrl}/ws`, '', '', {}); - - w.onmessage = onMessage; - - w.onopen = () => { - res(w); - }; - - w.onerror = (e) => { - console.error('socket closed:', e); - if (!rejected) { - rejected = true; + const connnect = (recon = () => {}) => { + try { + sockPromise.current = new Promise( + (res, rej) => { + try { + // eslint-disable-next-line new-cap + const w = new wsock.w3cwebsocket( + `${socketUrl}/ws`, + '', + '', + {} + ); + + w.onmessage = onMessage; + + w.onopen = () => { + res(w); + }; + + w.onerror = (e) => { + console.error(e); + recon(); + }; + + w.onclose = () => { + recon(); + }; + } catch (e) { rej(e); } - }; + } + ); + } catch (e) { + logger.error(e); + } + }; - w.onclose = () => {}; - } catch (e) { - rej(e); - } - }); - } catch (e) { - logger.error(e); - } + connnect(() => { + setTimeout(() => { + console.log('reconnecting'); + connnect(); + }, 1000); + }); } }, 1000,