fedimbed: error handle nodeinfo better
This commit is contained in:
parent
a08d44cde0
commit
4c08c14a43
1 changed files with 11 additions and 3 deletions
|
@ -44,9 +44,17 @@ async function resolvePlatform(url) {
|
|||
const urlObj = new URL(url);
|
||||
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},
|
||||
}).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) {
|
||||
logger.error("fedimbed", `No nodeinfo for "${urlObj.hostname}"???`);
|
||||
|
@ -123,7 +131,7 @@ async function processUrl(msg, url, spoiler = false) {
|
|||
url = urlObj.href;
|
||||
}
|
||||
|
||||
let platform = await resolvePlatform(url);
|
||||
let platform = await resolvePlatform(url) ?? "<no nodeinfo>";
|
||||
let color = PLATFORM_COLORS[platform];
|
||||
let platformName = platform
|
||||
.replace("gotosocial", "GoToSocial")
|
||||
|
|
Loading…
Reference in a new issue