generated from nhcarrigan/template
fix: make announcement route resilient to platform failures
✨ This commit was made with love from Hikari~ 🌸
This commit is contained in:
@@ -21,6 +21,12 @@ import type { FastifyPluginAsync } from "fastify";
|
||||
|
||||
const oneDay = 24 * 60 * 60 * 1000;
|
||||
|
||||
const getPlatformResult = (result: PromiseSettledResult<string>): string => {
|
||||
return result.status === "fulfilled"
|
||||
? result.value
|
||||
: `Unexpected error: ${String(result.reason)}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mounts the entry routes for the application. These routes
|
||||
* should not require CORS, as they are used by external services
|
||||
@@ -85,8 +91,8 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
|
||||
const announcement = await generateAnnouncements(content);
|
||||
|
||||
if (announcement === null) {
|
||||
return await reply.status(201).send({
|
||||
message: `Failed to generate announcements.`,
|
||||
return await reply.status(500).send({
|
||||
error: `Failed to generate announcements.`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,30 +111,30 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
|
||||
},
|
||||
});
|
||||
|
||||
const discordPost = await announceOnDiscord(
|
||||
markdownTitle,
|
||||
markdownContent,
|
||||
type,
|
||||
);
|
||||
const redditPost = await announceOnReddit(
|
||||
markdownTitle,
|
||||
markdownContent,
|
||||
type,
|
||||
);
|
||||
const blueskyPost = await announceOnBluesky(threaded);
|
||||
const twitterPost = await announceOnTwitter(threaded);
|
||||
const facebookPost = await announceOnFacebook(plaintext);
|
||||
const threadsPost = await announceOnThreads(threaded);
|
||||
const mastodonPost = await announceOnMastodon(threaded);
|
||||
const discoursePost = await announceOnDiscourse(
|
||||
markdownTitle,
|
||||
markdownContent,
|
||||
type,
|
||||
);
|
||||
const [
|
||||
discordResult,
|
||||
redditResult,
|
||||
blueskyResult,
|
||||
twitterResult,
|
||||
facebookResult,
|
||||
threadsResult,
|
||||
mastodonResult,
|
||||
discourseResult,
|
||||
] = await Promise.allSettled([
|
||||
announceOnDiscord(markdownTitle, markdownContent, type),
|
||||
announceOnReddit(markdownTitle, markdownContent, type),
|
||||
announceOnBluesky(threaded),
|
||||
announceOnTwitter(threaded),
|
||||
announceOnFacebook(plaintext),
|
||||
announceOnThreads(threaded),
|
||||
announceOnMastodon(threaded),
|
||||
announceOnDiscourse(markdownTitle, markdownContent, type),
|
||||
]);
|
||||
|
||||
return await reply.status(201).send({
|
||||
alert: `Please remember to manually post to: LinkedIn, Peerlist, Ko-fi, and Patreon.`,
|
||||
cost: announcement.cost,
|
||||
message: `Announcement processed. Discord: ${discordPost}, Reddit: ${redditPost}, Bluesky: ${blueskyPost}, Twitter: ${twitterPost}, Facebook: ${facebookPost}, Threads: ${threadsPost}, Mastodon: ${mastodonPost}, Discourse: ${discoursePost}`,
|
||||
message: `Announcement processed. Discord: ${getPlatformResult(discordResult)}, Reddit: ${getPlatformResult(redditResult)}, Bluesky: ${getPlatformResult(blueskyResult)}, Twitter: ${getPlatformResult(twitterResult)}, Facebook: ${getPlatformResult(facebookResult)}, Threads: ${getPlatformResult(threadsResult)}, Mastodon: ${getPlatformResult(mastodonResult)}, Discourse: ${getPlatformResult(discourseResult)}`,
|
||||
rawPost: announcement.response,
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user