diff --git a/scripts/db-export.ts b/scripts/db-export.ts index 29d347fc..08e9af69 100644 --- a/scripts/db-export.ts +++ b/scripts/db-export.ts @@ -102,8 +102,8 @@ async function exportEvents(args: ExportFilter) { let filter: NostrFilter = {}; try { filter = buildFilter(args); - } catch (e: any) { - die(1, e.message || e.toString()); + } catch (e) { + die(1, e instanceof Error ? e.message : e); } let count = 0; diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index f62ad76b..71397ee8 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -108,10 +108,10 @@ function connectStream(socket: WebSocket, ip: string | undefined) { for (const event of await store.query(filters, { limit: FILTER_LIMIT, timeout: Conf.db.timeouts.relay })) { send(['EVENT', subId, purifyEvent(event)]); } - } catch (e: any) { + } catch (e) { if (e instanceof RelayError) { send(['CLOSED', subId, e.message]); - } else if (e.message.includes('timeout')) { + } else if (e instanceof Error && e.message.includes('timeout')) { send(['CLOSED', subId, 'error: the relay could not respond fast enough']); } else { send(['CLOSED', subId, 'error: something went wrong']); diff --git a/src/storages/EventsDB.ts b/src/storages/EventsDB.ts index 208e0c72..4413ef5e 100644 --- a/src/storages/EventsDB.ts +++ b/src/storages/EventsDB.ts @@ -76,10 +76,10 @@ class EventsDB extends NPostgres { try { await super.event(event, { ...opts, timeout: opts.timeout ?? this.opts.timeout }); - } catch (e: any) { - if (e.message === 'Cannot add a deleted event') { + } catch (e) { + if (e instanceof Error && e.message === 'Cannot add a deleted event') { throw new RelayError('blocked', 'event deleted by user'); - } else if (e.message === 'Cannot replace an event with an older event') { + } else if (e instanceof Error && e.message === 'Cannot replace an event with an older event') { return; } else { throw e; diff --git a/src/trends.ts b/src/trends.ts index cf4f7c96..aced6800 100644 --- a/src/trends.ts +++ b/src/trends.ts @@ -113,8 +113,8 @@ export async function updateTrendingTags( await handleEvent(label, signal); console.info(`Trending ${l} updated.`); - } catch (e: any) { - console.error(`Error updating trending ${l}: ${e.message}`); + } catch (e) { + console.error(`Error updating trending ${l}: ${e instanceof Error ? e.message : e}`); } }