Effect CommunityEC
Effect Community2y ago
7 replies
Perry

How to catch SocketError and re-connect?

I'm using Socket from platform package to do client websocket connection. It all works fine, but socket is dropped like after 2 - 3 hrs, and I need to know what happened, and re-connect.

As you can see below, closeCodeIsError called log returns 1006 code. But I want to get more error details that's fired in ws.onerror, and do ws re-connection.

But as you can see here, fromWebSocket says
never
Error, which means i can't catch error here? I might misunderstand this as I'm not good at effect.ts yet. So, basically, I want to achieve 2 things;

- log error events (ws.onerror)
- re-connect when error happened

Much appreciated, thanks in advance!

import * as Socket from '@effect/platform/Socket'
// ...
const socket = yield* Socket.makeWebSocket(E.succeed(polymarketWebsocketUri!), {
            closeCodeIsError: (code) => {
              console.error('closeCodeIsError called', code, Socket.defaultCloseCodeIsError(code))
              return Socket.defaultCloseCodeIsError(code)
            },
          })
GitHub
An ecosystem of tools to build robust applications in TypeScript - Effect-TS/effect
effect/packages/platform/src/Socket.ts at main · Effect-TS/effect
Was this page helpful?