From 5ea7cd17d816faf00ea642aee1cc85af8c3ecc84 Mon Sep 17 00:00:00 2001 From: kieran Date: Tue, 18 Jun 2024 12:05:28 +0100 Subject: [PATCH] fix: fail after local relay --- packages/system/src/connection-pool.ts | 1 + packages/system/src/connection.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/system/src/connection-pool.ts b/packages/system/src/connection-pool.ts index dad5eace..ffcd5215 100644 --- a/packages/system/src/connection-pool.ts +++ b/packages/system/src/connection-pool.ts @@ -13,6 +13,7 @@ import { ConnectionSyncModule, DefaultSyncModule } from "./sync/connection"; export interface ConnectionTypeEvents { change: () => void; connected: (wasReconnect: boolean) => void; + error: () => void; event: (sub: string, e: TaggedNostrEvent) => void; eose: (sub: string) => void; closed: (sub: string, reason: string) => void; diff --git a/packages/system/src/connection.ts b/packages/system/src/connection.ts index e41c764f..5ed36410 100644 --- a/packages/system/src/connection.ts +++ b/packages/system/src/connection.ts @@ -150,7 +150,10 @@ export class Connection extends EventEmitter implements Co this.Socket.onerror = e => this.#onError(e); this.Socket.onclose = e => this.#onClose(e); if (awaitOpen) { - await new Promise(resolve => this.once("connected", resolve)); + await new Promise((resolve, reject) => { + this.once("connected", resolve); + this.once("error", reject); + }); } } catch (e) { this.#connectStarted = false; @@ -276,6 +279,7 @@ export class Connection extends EventEmitter implements Co #onError(e: WebSocket.Event) { this.#log("Error: %O", e); this.emit("change"); + this.emit("error"); } /**