Skip to content

Commit

Permalink
catch error if websocket is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Oct 14, 2024
1 parent 5057319 commit 72bb226
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/store-sync/src/wiresaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ export function watchLogs({ url, address, fromBlock }: WatchLogsInput): WatchLog
});

// Catch up to the pending logs
const initialLogs = await fetchInitialLogs({ client, address, fromBlock, topics });
const logs = [...initialLogs, ...logBuffer].sort(logSort);
const blockNumber = logs.at(-1)?.blockNumber ?? fromBlock;
subscriber.next({ blockNumber, logs: initialLogs });
caughtUp = true;
try {
const initialLogs = await fetchInitialLogs({ client, address, fromBlock, topics });
const logs = [...initialLogs, ...logBuffer].sort(logSort);
const blockNumber = logs.at(-1)?.blockNumber ?? fromBlock;
subscriber.next({ blockNumber, logs: initialLogs });
caughtUp = true;
} catch (e) {
subscriber.error("Could not fetch initial wiresaw logs");
}
});

return () => client?.close();
Expand Down

0 comments on commit 72bb226

Please sign in to comment.