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
|
// Fetch post
|
||||||
let rawPostData;
|
let rawPostData;
|
||||||
rawPostData = await signedFetch(url, {
|
try {
|
||||||
headers: {
|
rawPostData = await signedFetch(url, {
|
||||||
"User-Agent": FRIENDLY_USERAGENT,
|
headers: {
|
||||||
Accept: "application/activity+json",
|
"User-Agent": FRIENDLY_USERAGENT,
|
||||||
},
|
Accept: "application/activity+json",
|
||||||
})
|
},
|
||||||
.then((res) => res.text())
|
}).then((res) => res.text());
|
||||||
.catch(async (err) => {
|
} catch (err) {
|
||||||
logger.error(
|
logger.error(
|
||||||
"fedimbed",
|
"fedimbed",
|
||||||
`Failed to signed fetch "${url}", retrying unsigned: ${err}`
|
`Failed to signed fetch "${url}", retrying unsigned: ${err}`
|
||||||
);
|
);
|
||||||
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;
|
||||||
if (rawPostData?.startsWith("{")) {
|
if (rawPostData?.startsWith("{")) {
|
||||||
|
@ -209,36 +209,36 @@ async function processUrl(msg, url, spoiler = false) {
|
||||||
)}, ${JSON.stringify(headers)}`
|
)}, ${JSON.stringify(headers)}`
|
||||||
);
|
);
|
||||||
let rawPostData2;
|
let rawPostData2;
|
||||||
rawPostData2 = await signedFetch(
|
try {
|
||||||
redirUrl,
|
rawPostData2 = await signedFetch(
|
||||||
Object.assign(options, {
|
redirUrl,
|
||||||
headers: Object.assign(headers, {
|
Object.assign(options, {
|
||||||
"User-Agent": FRIENDLY_USERAGENT,
|
headers: Object.assign(headers, {
|
||||||
}),
|
"User-Agent": FRIENDLY_USERAGENT,
|
||||||
})
|
}),
|
||||||
)
|
})
|
||||||
.then((res) => res.text())
|
).then((res) => res.text());
|
||||||
.catch(async (err) => {
|
} catch (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}`
|
||||||
);
|
);
|
||||||
rawPostData2 = await signedFetch(
|
rawPostData2 = await signedFetch(
|
||||||
redirUrl,
|
redirUrl,
|
||||||
Object.assign(options, {
|
Object.assign(options, {
|
||||||
headers: Object.assign(headers, {
|
headers: Object.assign(headers, {
|
||||||
"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;
|
||||||
if (rawPostData2?.startsWith("{")) {
|
if (rawPostData2?.startsWith("{")) {
|
||||||
|
|
Loading…
Reference in a new issue