fix corner cases when creating invites

This commit is contained in:
Andre Staltz 2024-01-31 14:34:42 +02:00
parent 731395ea97
commit 745eea3de0
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 6 additions and 7 deletions

View File

@ -114,7 +114,6 @@ function parseJoinCommand(pieces, uri) {
function parseFollowCommand(pieces, uri) { function parseFollowCommand(pieces, uri) {
const [label, id] = pieces const [label, id] = pieces
if (!id) { if (!id) {
// prettier-ignore
throw new Error(`Invalid URI "${uri}" for invite.parse, missing follow id`) throw new Error(`Invalid URI "${uri}" for invite.parse, missing follow id`)
} }
pieces.shift() pieces.shift()
@ -213,14 +212,12 @@ function parsePromiseAccountAddCommand(pieces, uri) {
function parse(uri) { function parse(uri) {
const url = new URL(uri) const url = new URL(uri)
if (url.protocol !== 'ppppp:') { if (url.protocol !== 'ppppp:') {
throw new Error( // prettier-ignore
`Invalid protocol in URI "${uri}" for invite.parse, expected "ppppp:"` throw new Error(`Invalid protocol in URI "${uri}" for invite.parse, expected "ppppp:"`)
)
} }
if (url.host !== 'invite') { if (url.host !== 'invite') {
throw new Error( // prettier-ignore
`Invalid host in URI "${uri}" for invite.parse, expected "invite"` throw new Error(`Invalid host in URI "${uri}" for invite.parse, expected "invite"`)
)
} }
const pieces = url.pathname.startsWith('/') const pieces = url.pathname.startsWith('/')
? url.pathname.substring(1).split('/') ? url.pathname.substring(1).split('/')
@ -291,6 +288,8 @@ async function makeJoinCommands(peer, amountHubs, hardcodedHub) {
: await p(peer.hubClient.getHubs)(amountHubs) : await p(peer.hubClient.getHubs)(amountHubs)
// prettier-ignore // prettier-ignore
if (err1) return [new Error('Failed to get hubs while creating invite', { cause: err1 })] if (err1) return [new Error('Failed to get hubs while creating invite', { cause: err1 })]
// prettier-ignore
if (hubMultiaddrs.length === 0) return [new Error('No hubs available while creating invite')]
// For each hub, connect and create token // For each hub, connect and create token
const hubErrors = [] const hubErrors = []