fedimbed: error handle nodeinfo better

This commit is contained in:
Cynthia Foxwell 2023-12-02 01:01:06 -07:00
parent a08d44cde0
commit 4c08c14a43
1 changed files with 11 additions and 3 deletions

View File

@ -44,9 +44,17 @@ async function resolvePlatform(url) {
const urlObj = new URL(url); const urlObj = new URL(url);
if (domainCache.has(urlObj.hostname)) return domainCache.get(urlObj.hostname); if (domainCache.has(urlObj.hostname)) return domainCache.get(urlObj.hostname);
const probe = await fetch(urlObj.origin + "/.well-known/nodeinfo", { const res = await fetch(urlObj.origin + "/.well-known/nodeinfo", {
headers: {"User-Agent": FRIENDLY_USERAGENT}, headers: {"User-Agent": FRIENDLY_USERAGENT},
}).then((res) => res.json()); }).then((res) => res.text());
if (!res.startsWith("{")) {
logger.error("fedimbed", `No nodeinfo for "${urlObj.hostname}"???`);
domainCache.set(urlObj.hostname, null);
return null;
}
const probe = JSON.parse(res);
if (!probe?.links) { if (!probe?.links) {
logger.error("fedimbed", `No nodeinfo for "${urlObj.hostname}"???`); logger.error("fedimbed", `No nodeinfo for "${urlObj.hostname}"???`);
@ -123,7 +131,7 @@ async function processUrl(msg, url, spoiler = false) {
url = urlObj.href; url = urlObj.href;
} }
let platform = await resolvePlatform(url); let platform = await resolvePlatform(url) ?? "<no nodeinfo>";
let color = PLATFORM_COLORS[platform]; let color = PLATFORM_COLORS[platform];
let platformName = platform let platformName = platform
.replace("gotosocial", "GoToSocial") .replace("gotosocial", "GoToSocial")