From 40824280b460b29e1a29a3052147d73f51c6659a Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Wed, 26 Feb 2025 19:53:55 -0300 Subject: [PATCH 1/3] fix: call remove if it's available --- packages/ditto/controllers/api/admin.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/ditto/controllers/api/admin.ts b/packages/ditto/controllers/api/admin.ts index 411aa841..e393df46 100644 --- a/packages/ditto/controllers/api/admin.ts +++ b/packages/ditto/controllers/api/admin.ts @@ -160,11 +160,13 @@ const adminActionController: AppController = async (c) => { } if (data.type === 'revoke_name') { n.revoke_name = true; - relay.remove!([{ kinds: [30360], authors: [await conf.signer.getPublicKey()], '#p': [authorId] }]).catch( - (e: unknown) => { - logi({ level: 'error', ns: 'ditto.api.admin.account.action', type: data.type, error: errorJson(e) }); - }, - ); + if (relay.remove) { + relay.remove([{ kinds: [30360], authors: [await conf.signer.getPublicKey()], '#p': [authorId] }]).catch( + (e: unknown) => { + logi({ level: 'error', ns: 'ditto.api.admin.account.action', type: data.type, error: errorJson(e) }); + }, + ); + } } await updateUser(authorId, n, c); From 0c7ab0364339511ab72079544bb43346ff236620 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Wed, 26 Feb 2025 20:06:57 -0300 Subject: [PATCH 2/3] refactor: use ?. --- packages/ditto/controllers/api/admin.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/ditto/controllers/api/admin.ts b/packages/ditto/controllers/api/admin.ts index e393df46..d8d03eb9 100644 --- a/packages/ditto/controllers/api/admin.ts +++ b/packages/ditto/controllers/api/admin.ts @@ -160,13 +160,11 @@ const adminActionController: AppController = async (c) => { } if (data.type === 'revoke_name') { n.revoke_name = true; - if (relay.remove) { - relay.remove([{ kinds: [30360], authors: [await conf.signer.getPublicKey()], '#p': [authorId] }]).catch( - (e: unknown) => { - logi({ level: 'error', ns: 'ditto.api.admin.account.action', type: data.type, error: errorJson(e) }); - }, - ); - } + relay.remove?.([{ kinds: [30360], authors: [await conf.signer.getPublicKey()], '#p': [authorId] }]).catch( + (e: unknown) => { + logi({ level: 'error', ns: 'ditto.api.admin.account.action', type: data.type, error: errorJson(e) }); + }, + ); } await updateUser(authorId, n, c); From 0f20f1b26b156190462186b52cb2f80a7c8ccd16 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Wed, 26 Feb 2025 20:21:42 -0300 Subject: [PATCH 3/3] refactor: return 500 http code in case of error --- packages/ditto/controllers/api/admin.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/ditto/controllers/api/admin.ts b/packages/ditto/controllers/api/admin.ts index d8d03eb9..f3611035 100644 --- a/packages/ditto/controllers/api/admin.ts +++ b/packages/ditto/controllers/api/admin.ts @@ -160,11 +160,12 @@ const adminActionController: AppController = async (c) => { } if (data.type === 'revoke_name') { n.revoke_name = true; - relay.remove?.([{ kinds: [30360], authors: [await conf.signer.getPublicKey()], '#p': [authorId] }]).catch( - (e: unknown) => { - logi({ level: 'error', ns: 'ditto.api.admin.account.action', type: data.type, error: errorJson(e) }); - }, - ); + try { + await relay.remove!([{ kinds: [30360], authors: [await conf.signer.getPublicKey()], '#p': [authorId] }]); + } catch (e) { + logi({ level: 'error', ns: 'ditto.api.admin.account.action', type: data.type, error: errorJson(e) }); + return c.json({ error: 'Unexpected runtime error' }, 500); + } } await updateUser(authorId, n, c);