From 608400d010262d3e2dc59cd03508a608560b521b Mon Sep 17 00:00:00 2001 From: Davinci Date: Mon, 13 May 2024 13:11:52 +0200 Subject: [PATCH 1/2] fix: failed DM error handling --- src/controllers/NostrController.ts | 18 ++++++++++++++++-- src/utils/misc.ts | 11 ++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/controllers/NostrController.ts b/src/controllers/NostrController.ts index a2b0f1e..ac3fbf9 100644 --- a/src/controllers/NostrController.ts +++ b/src/controllers/NostrController.ts @@ -214,8 +214,22 @@ export class NostrController extends EventEmitter { } }) - if (publishedRelays.length === 0) - throw new Error(`Couldn't publish to any relay`) + if (publishedRelays.length === 0) { + const failedPublishes: any[] = [] + + results.forEach((res, index) => { + if (res.status === 'rejected') { + failedPublishes.push( + { + relay: relays[index], + error: res.reason.message + } + ) + } + }) + + throw failedPublishes + } return publishedRelays } diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 3a0c0cd..841b9fa 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -157,9 +157,14 @@ export const sendDM = async ( .then((relays) => { toast.success(`Encrypted DM sent on: ${relays.join('\n')}`) }) - .catch((err) => { - console.log('err :>> ', err) - toast.error(err.message || 'An error occurred while publishing DM') + .catch((errResults) => { + console.log('err :>> ', errResults) + toast.error('An error occurred while publishing DM') + + errResults.forEach((errResult: any) => { + toast.error(`${errResult.relay} -- ${errResult.error}`) + }) + return null }) } -- 2.34.1 From f6a2f4aa48d4411b0ba6056a575cd190f43b9fe0 Mon Sep 17 00:00:00 2001 From: Davinci Date: Tue, 14 May 2024 17:20:19 +0200 Subject: [PATCH 2/2] chore: error message --- src/utils/misc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 3716b66..6f5922c 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -166,7 +166,7 @@ export const sendDM = async ( toast.error('An error occurred while publishing DM') errResults.forEach((errResult: any) => { - toast.error(`${errResult.relay} -- ${errResult.error}`) + toast.error(`Publishing to ${errResult.relay} caused the following error: ${errResult.error}`) }) return null -- 2.34.1