Skip to content

Commit

Permalink
Improve/error handling (#143)
Browse files Browse the repository at this point in the history
* 🎨 Improved error handling for serverside
  • Loading branch information
abdheshnayak authored Mar 14, 2024
1 parent 8c70ea3 commit 97062c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion web/lib/client/components/logger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ const LogComp = ({
{isLoading && <LoadingComp />}

{errors.length ? (
<pre>{JSON.stringify(errors)}</pre>
<pre>{JSON.stringify(errors, null, 2)}</pre>
) : (
logs.length > 0 && (
<LogBlock
Expand Down
66 changes: 40 additions & 26 deletions web/lib/client/helpers/socket/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,35 +226,49 @@ export const SockProvider = ({ children }: ChildrenProps) => {
useDebounce(
() => {
if (typeof window !== 'undefined') {
try {
sockPromise.current = new Promise<wsock.w3cwebsocket>((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<wsock.w3cwebsocket>(
(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,
Expand Down

0 comments on commit 97062c9

Please sign in to comment.