diff --git a/ts/services/username.ts b/ts/services/username.ts index 4fa34cec9d93..54281ba536a5 100644 --- a/ts/services/username.ts +++ b/ts/services/username.ts @@ -274,7 +274,7 @@ const USERNAME_LINK_ENTROPY_SIZE = 32; export async function resolveUsernameByLinkBase64( base64: string -): Promise { +): Promise { const { server } = window.textsecure; if (!server) { throw new Error('server interface is not available!'); @@ -288,12 +288,19 @@ export async function resolveUsernameByLinkBase64( strictAssert(serverId, 'Failed to re-encode server id as uuid'); strictAssert(window.textsecure.server, 'WebAPI must be available'); - const { usernameLinkEncryptedValue } = await server.resolveUsernameLink( - serverId - ); + try { + const { usernameLinkEncryptedValue } = await server.resolveUsernameLink( + serverId + ); - return usernames.decryptUsernameLink({ - entropy: Buffer.from(entropy), - encryptedUsername: Buffer.from(usernameLinkEncryptedValue), - }); + return usernames.decryptUsernameLink({ + entropy: Buffer.from(entropy), + encryptedUsername: Buffer.from(usernameLinkEncryptedValue), + }); + } catch (error) { + if (error instanceof HTTPError && error.code === 404) { + return undefined; + } + throw error; + } } diff --git a/ts/util/createIPCEvents.ts b/ts/util/createIPCEvents.ts index 9e6d53bc88ef..2f23c6f500f4 100644 --- a/ts/util/createIPCEvents.ts +++ b/ts/util/createIPCEvents.ts @@ -566,9 +566,12 @@ export function createIPCEvents( } const maybeUsernameBase64 = parseUsernameBase64FromSignalDotMeHash(hash); + let username: string | undefined; if (maybeUsernameBase64) { - const username = await resolveUsernameByLinkBase64(maybeUsernameBase64); + username = await resolveUsernameByLinkBase64(maybeUsernameBase64); + } + if (username) { const convoId = await lookupConversationWithoutServiceId({ type: 'username', username,