Handle WebSocket#error event

This commit is contained in:
ayntee
2020-11-24 21:47:25 +04:00
parent 6041e03268
commit c5cd88852b

View File

@@ -63,8 +63,9 @@ export async function createShard(
}
};
// TODO: handle the WebSocket#error event
// socket.onerror = () => {};
socket.onerror = ({ timeStamp }) => {
eventHandlers.debug?.({ type: "websocketErrored", data: { timeStamp } });
};
socket.onmessage = ({ data: message }) => {
if (message instanceof ArrayBuffer) {
@@ -160,6 +161,7 @@ export async function createShard(
"Shard.ts: Error occurred that is not resumeable or able to be reconnected.",
);
}
// These error codes can not be resumed but need to reconnect from start
if ([4003, 4007, 4008, 4009].includes(code)) {
eventHandlers.debug?.(