fedimbed: mastoapi error handling

This commit is contained in:
Cynthia Foxwell 2022-12-05 21:18:28 -07:00
parent 65efa56ee1
commit e181188fa7

View file

@ -129,12 +129,15 @@ async function processUrl(msg, url) {
} }
if (redirUrl) { if (redirUrl) {
const postData2 = await fetch(url.replace("notice", "api/v1/statuses"), { const rawPostData2 = await fetch(
headers: { url.replace("notice", "api/v1/statuses"),
"User-Agent": FRIENDLY_USERAGENT, {
}, headers: {
}) "User-Agent": FRIENDLY_USERAGENT,
.then((res) => res.json()) },
}
)
.then((res) => res.text())
.catch((err) => { .catch((err) => {
logger.error( logger.error(
"fedimbed", "fedimbed",
@ -142,6 +145,13 @@ async function processUrl(msg, url) {
); );
}); });
let postData2;
if (rawPostData2.startsWith("{")) {
postData2 = JSON.parse(rawPostData2);
} else {
logger.warn("fedimbed", `Got non-JSON for "${url}" as MastoAPI: ${rawPostData2}`);
}
if (!postData2) { if (!postData2) {
logger.warn( logger.warn(
"fedimbed", "fedimbed",