fedimbed: try with if instead of catch

This commit is contained in:
Cynthia Foxwell 2023-07-27 21:19:24 -06:00
parent 3ee873082c
commit 2aa5adc1ed

View file

@ -128,16 +128,18 @@ async function processUrl(msg, url, spoiler = false) {
"fedimbed", "fedimbed",
`Failed to signed fetch "${url}", retrying unsigned: ${err}` `Failed to signed fetch "${url}", retrying unsigned: ${err}`
); );
}
if (!rawPostData) {
try {
rawPostData = await fetch(url, { rawPostData = await fetch(url, {
headers: { headers: {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
Accept: "application/activity+json", Accept: "application/activity+json",
}, },
}) }).then((res) => res.text());
.then((res) => res.text()) } catch (err) {
.catch((err) => {
logger.error("fedimbed", `Failed to fetch "${url}": ${err}`); logger.error("fedimbed", `Failed to fetch "${url}": ${err}`);
}); }
} }
let postData; let postData;
@ -223,6 +225,9 @@ async function processUrl(msg, url, spoiler = false) {
"fedimbed", "fedimbed",
`Failed to signed fetch "${url}" via MastoAPI, retrying unsigned: ${err}` `Failed to signed fetch "${url}" via MastoAPI, retrying unsigned: ${err}`
); );
}
if (!rawPostData2) {
try {
rawPostData2 = await signedFetch( rawPostData2 = await signedFetch(
redirUrl, redirUrl,
Object.assign(options, { Object.assign(options, {
@ -230,14 +235,13 @@ async function processUrl(msg, url, spoiler = false) {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
}), }),
}) })
) ).then((res) => res.text());
.then((res) => res.text()) } catch (err) {
.catch((err) => {
logger.error( logger.error(
"fedimbed", "fedimbed",
`Failed to fetch "${url}" via MastoAPI: ${err}` `Failed to fetch "${url}" via MastoAPI: ${err}`
); );
}); }
} }
let postData2; let postData2;