From 5e6594d91d3738f3e5da6a60232e34ee13546fb5 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 7 Jul 2023 18:58:24 +0200 Subject: [PATCH] [mastodon-client] Fail gracefully if user resolve fails --- packages/megalodon/src/misskey.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index 5275c70f6..61464522a 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1257,31 +1257,31 @@ export default class Misskey implements MegalodonInterface { } public async getMentions(text: string, cache: AccountCache): Promise { - console.log(`getting mentions for message: '${text}'`); const mentions :Entity.Mention[] = []; if (text == undefined) return mentions; - console.log('text is not undefined, continuing'); - const mentionMatch = text.matchAll(/(?<=^|\s)@(?.*?)(?:@(?.*?)|)(?=\s|$)/g); for (const m of mentionMatch) { - if (m.groups == null) - continue; + try { + if (m.groups == null) + continue; - const account = await this.getAccountByNameCached(m.groups.user, m.groups.host, cache); + const account = await this.getAccountByNameCached(m.groups.user, m.groups.host, cache); - if (account == null) - continue; + if (account == null) + continue; - mentions.push({ - id: account.id, - url: account.url, - username: account.username, - acct: account.acct - }); + mentions.push({ + id: account.id, + url: account.url, + username: account.username, + acct: account.acct + }); + } + catch {} } return mentions;