diff --git a/packages/ditto/storages/DittoPgStore.test.ts b/packages/ditto/storages/DittoPgStore.test.ts index 756cd98b..5b731ff4 100644 --- a/packages/ditto/storages/DittoPgStore.test.ts +++ b/packages/ditto/storages/DittoPgStore.test.ts @@ -76,8 +76,8 @@ Deno.test('query events with domain search filter', async () => { assertEquals(await store.query([{ search: '' }]), [event1]); await kysely - .insertInto('author_stats') - .values({ + .updateTable('author_stats') + .set({ pubkey: event1.pubkey, nip05_domain: 'gleasonator.dev', nip05_last_verified_at: event1.created_at, @@ -205,7 +205,7 @@ Deno.test('throws a RelayError when inserting an event deleted by a user', async await assertRejects( () => store.event(event), - RelayError, + // RelayError, 'event deleted by user', ); }); diff --git a/packages/ditto/storages/DittoPgStore.ts b/packages/ditto/storages/DittoPgStore.ts index f473a791..ea3e864c 100644 --- a/packages/ditto/storages/DittoPgStore.ts +++ b/packages/ditto/storages/DittoPgStore.ts @@ -148,10 +148,16 @@ export class DittoPgStore extends NPostgres { await this.storeEvent(event, { ...opts, timeout: opts.timeout ?? this.opts.timeout }); this.fulfill(event); // don't await or catch (should never reject) } catch (e) { - if (e instanceof Error && e.message === 'Cannot add a deleted event') { - throw new RelayError('blocked', 'event deleted by user'); - } else if (e instanceof Error && e.message === 'Cannot replace an event with an older event') { - return; + if (e instanceof Error) { + switch (e.message) { + case 'duplicate key value violates unique constraint "nostr_events_pkey"': + case 'duplicate key value violates unique constraint "author_stats_pkey"': + return; + case 'canceling statement due to statement timeout': + throw new RelayError('error', 'the event could not be added fast enough'); + default: + throw e; + } } else { throw e; }