fedimbed: better error handling

This commit is contained in:
Cynthia Foxwell 2022-12-05 19:59:43 -07:00
parent 909bec67e1
commit e0c699acf5

View file

@ -71,20 +71,26 @@ async function processUrl(msg, url) {
let content, cw, author;
// Fetch post
const postData = await fetch(url, {
const rawPostData = await fetch(url, {
headers: {
"User-Agent": FRIENDLY_USERAGENT,
Accept: "application/activity+json",
},
})
.then((res) => res.json())
.then((res) => res.text())
.catch((err) => {
logger.error("fedimbed", `Failed to fetch "${url}" as AS2: ${err}`);
});
if (postData.error) {
let postData;
if (rawPostData.startsWith("{") {
postData = JSON.parse(rawPostData);
} else {
logger.error("fedimbed", `Got non-JSON for "${url}": ${rawPostData}`);
}
if (postData?.error) {
logger.error("fedimbed", `Received error for "${url}": ${postData.error}`);
return;
}
if (!postData) {