Skip to content

Commit

Permalink
Initiliaze failerRelays as undefined but handle error explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinKelsay committed Feb 19, 2024
1 parent f92f333 commit 68923eb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/use-crossposter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -178,7 +179,7 @@ export default function useCrossposter () {
}

const crosspostItem = async item => {
let failedRelays = []
let failedRelays;
let allSuccessful = false
let noteId

Expand All @@ -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) || []

Expand All @@ -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))
Expand Down

0 comments on commit 68923eb

Please sign in to comment.