From 68923ebafde5d9236b5e5d5b8834fac96c92b6bd Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Mon, 19 Feb 2024 13:49:12 -0600 Subject: [PATCH] Initiliaze failerRelays as undefined but handle error explicitly --- components/use-crossposter.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/use-crossposter.js b/components/use-crossposter.js index d689ff830..0f1f9ebda 100644 --- a/components/use-crossposter.js +++ b/components/use-crossposter.js @@ -5,6 +5,7 @@ import { DEFAULT_CROSSPOSTING_RELAYS, crosspost, callWithTimeout } from '../lib/ import { gql, useMutation, useQuery, useLazyQuery } from '@apollo/client' import { SETTINGS } from '../fragments/users' import { ITEM_FULL_FIELDS, POLL_FIELDS } from '../fragments/items' +import { re } from 'mathjs' async function discussionToEvent (item) { const createdAt = Math.floor(Date.now() / 1000) @@ -178,7 +179,7 @@ export default function useCrossposter () { } const crosspostItem = async item => { - let failedRelays = [] + let failedRelays; let allSuccessful = false let noteId @@ -189,6 +190,11 @@ export default function useCrossposter () { try { const result = await crosspost(event, failedRelays || relays) + if (result.error) { + failedRelays = []; + throw new Error(result.error) + } + noteId = result.noteId failedRelays = result?.failedRelays?.map(relayObj => relayObj.relay) || [] @@ -206,7 +212,6 @@ export default function useCrossposter () { } } catch (error) { await crosspostError(error.message) - failedRelays = [] // wait 2 seconds to show error then break await new Promise(resolve => setTimeout(resolve, 2000))