Remove e: any from error handlers

This commit is contained in:
Alex Gleason 2024-11-22 10:26:30 -06:00
parent ebaf2b9c59
commit 4eb7ea2461
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 9 additions and 9 deletions

View file

@ -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;

View file

@ -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']);

View file

@ -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;

View file

@ -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}`);
}
}