fedimbed: async Promise.catch fails, use try catch

This commit is contained in:
Cynthia Foxwell 2023-07-27 21:16:15 -06:00
parent e611a7865e
commit 3ee873082c

View file

@ -116,14 +116,14 @@ async function processUrl(msg, url, spoiler = false) {
// Fetch post // Fetch post
let rawPostData; let rawPostData;
try {
rawPostData = await signedFetch(url, { rawPostData = await signedFetch(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(async (err) => {
logger.error( logger.error(
"fedimbed", "fedimbed",
`Failed to signed fetch "${url}", retrying unsigned: ${err}` `Failed to signed fetch "${url}", retrying unsigned: ${err}`
@ -138,7 +138,7 @@ async function processUrl(msg, url, spoiler = false) {
.catch((err) => { .catch((err) => {
logger.error("fedimbed", `Failed to fetch "${url}": ${err}`); logger.error("fedimbed", `Failed to fetch "${url}": ${err}`);
}); });
}); }
let postData; let postData;
if (rawPostData?.startsWith("{")) { if (rawPostData?.startsWith("{")) {
@ -209,6 +209,7 @@ async function processUrl(msg, url, spoiler = false) {
)}, ${JSON.stringify(headers)}` )}, ${JSON.stringify(headers)}`
); );
let rawPostData2; let rawPostData2;
try {
rawPostData2 = await signedFetch( rawPostData2 = await signedFetch(
redirUrl, redirUrl,
Object.assign(options, { Object.assign(options, {
@ -216,9 +217,8 @@ 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(async (err) => {
logger.error( logger.error(
"fedimbed", "fedimbed",
`Failed to signed fetch "${url}" via MastoAPI, retrying unsigned: ${err}` `Failed to signed fetch "${url}" via MastoAPI, retrying unsigned: ${err}`
@ -238,7 +238,7 @@ async function processUrl(msg, url, spoiler = false) {
`Failed to fetch "${url}" via MastoAPI: ${err}` `Failed to fetch "${url}" via MastoAPI: ${err}`
); );
}); });
}); }
let postData2; let postData2;
if (rawPostData2?.startsWith("{")) { if (rawPostData2?.startsWith("{")) {