fedimbed: async Promise.catch fails, use try catch
This commit is contained in:
parent
e611a7865e
commit
3ee873082c
1 changed files with 53 additions and 53 deletions
|
@ -116,29 +116,29 @@ async function processUrl(msg, url, spoiler = false) {
|
|||
|
||||
// Fetch post
|
||||
let rawPostData;
|
||||
rawPostData = await signedFetch(url, {
|
||||
headers: {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
Accept: "application/activity+json",
|
||||
},
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.catch(async (err) => {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to signed fetch "${url}", retrying unsigned: ${err}`
|
||||
);
|
||||
rawPostData = await fetch(url, {
|
||||
headers: {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
Accept: "application/activity+json",
|
||||
},
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
logger.error("fedimbed", `Failed to fetch "${url}": ${err}`);
|
||||
});
|
||||
});
|
||||
try {
|
||||
rawPostData = await signedFetch(url, {
|
||||
headers: {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
Accept: "application/activity+json",
|
||||
},
|
||||
}).then((res) => res.text());
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to signed fetch "${url}", retrying unsigned: ${err}`
|
||||
);
|
||||
rawPostData = await fetch(url, {
|
||||
headers: {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
Accept: "application/activity+json",
|
||||
},
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
logger.error("fedimbed", `Failed to fetch "${url}": ${err}`);
|
||||
});
|
||||
}
|
||||
|
||||
let postData;
|
||||
if (rawPostData?.startsWith("{")) {
|
||||
|
@ -209,36 +209,36 @@ async function processUrl(msg, url, spoiler = false) {
|
|||
)}, ${JSON.stringify(headers)}`
|
||||
);
|
||||
let rawPostData2;
|
||||
rawPostData2 = await signedFetch(
|
||||
redirUrl,
|
||||
Object.assign(options, {
|
||||
headers: Object.assign(headers, {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => res.text())
|
||||
.catch(async (err) => {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to signed fetch "${url}" via MastoAPI, retrying unsigned: ${err}`
|
||||
);
|
||||
rawPostData2 = await signedFetch(
|
||||
redirUrl,
|
||||
Object.assign(options, {
|
||||
headers: Object.assign(headers, {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to fetch "${url}" via MastoAPI: ${err}`
|
||||
);
|
||||
});
|
||||
});
|
||||
try {
|
||||
rawPostData2 = await signedFetch(
|
||||
redirUrl,
|
||||
Object.assign(options, {
|
||||
headers: Object.assign(headers, {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
}),
|
||||
})
|
||||
).then((res) => res.text());
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to signed fetch "${url}" via MastoAPI, retrying unsigned: ${err}`
|
||||
);
|
||||
rawPostData2 = await signedFetch(
|
||||
redirUrl,
|
||||
Object.assign(options, {
|
||||
headers: Object.assign(headers, {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to fetch "${url}" via MastoAPI: ${err}`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
let postData2;
|
||||
if (rawPostData2?.startsWith("{")) {
|
||||
|
|
Loading…
Reference in a new issue