From 6d80fa565b010fd2d2cb761c412de61d233a58b6 Mon Sep 17 00:00:00 2001 From: Natty Date: Thu, 31 Aug 2023 19:48:45 +0200 Subject: [PATCH] Gracefully fall-back to the tag handle for accounts that do not pass the first lookup --- create-circle.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/create-circle.js b/create-circle.js index 041823c..bbea8bc 100644 --- a/create-circle.js +++ b/create-circle.js @@ -12,6 +12,13 @@ async function apiRequest(url, options = null) } return await fetch(url, options ?? {}) + .then(response => { + if (response.ok) { + return response; + } + + throw new Error(`Error fetching ${url}: ${response.status} ${response.statusText}`); + }) .then(response => response.json()) .catch(error => { console.error(`Error fetching ${url}: ${error}`); @@ -267,7 +274,12 @@ class MastodonApiClient extends ApiClient { async getUserIdFromHandle(handle) { const url = `https://${this._instance}/api/v1/accounts/lookup?acct=${handle.baseHandle}`; - const response = await apiRequest(url, null); + let response = await apiRequest(url, null); + + if (!response) { + const url = `https://${this._instance}/api/v1/accounts/lookup?acct=${handle}`; + response = await apiRequest(url, null); + } if (!response) { return null;