Skip to content

Open-source status page, incident response and uptime monitoring

chore: feed route error handling (#1564)

Maximilian Kaskef781b1f0f84d
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/feed/[type]/route.ts b/apps/status-page/src/app/(status-page)/[domain]/(public)/feed/[type]/route.ts
index 394ca46f8..70e58bc77 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/(public)/feed/[type]/route.ts
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/feed/[type]/route.ts
@@ -17,91 +17,94 @@ export async function GET(
_request: Request,
props: { params: Promise<{ domain: string; type: string }> },
) {
- const queryClient = getQueryClient();
- const { domain, type } = await props.params;
- if (!["rss", "atom"].includes(type)) return notFound();
+ try {
+ const queryClient = getQueryClient();
+ const { domain, type } = await props.params;
+ if (!["rss", "atom"].includes(type)) return notFound();
- const page = await queryClient.fetchQuery(
- trpc.page.getPageBySlug.queryOptions({ slug: domain }),
- );
- if (!page) return notFound();
+ const page = await queryClient.fetchQuery(
+ trpc.page.getPageBySlug.queryOptions({ slug: domain }),
+ );
+ if (!page) return notFound();
- if (page.passwordProtected) {
- const url = new URL(_request.url);
- const password = url.searchParams.get("pw");
- if (password !== page.password) return unauthorized();
- }
-
- const baseUrl = getBaseUrl({
- slug: page.slug,
- customDomain: page.customDomain,
- });
+ if (page.passwordProtected) {
+ const url = new URL(_request.url);
+ const password = url.searchParams.get("pw");
+ if (password !== page.password) return unauthorized();
+ }
- const feed = new Feed({
- id: `${baseUrl}/feed/${type}`,
- title: page.title,
- description: page.description,
- generator: "OpenStatus - Status Page Updates",
- feedLinks: {
- rss: `${baseUrl}/feed/rss`,
- atom: `${baseUrl}/feed/atom`,
- },
- link: baseUrl,
- author: {
- name: page.title,
- email:
- page.contactUrl?.startsWith("mailto:") && page.contactUrl !== null
- ? page.contactUrl.slice(7)
- : undefined,
- link: page.homepageUrl || baseUrl,
- },
- copyright: `Copyright ${new Date()
- .getFullYear()
- .toString()} openstatus.dev`,
- language: "en-US",
- updated: new Date(),
- ttl: 60,
- });
+ const baseUrl = getBaseUrl({
+ slug: page.slug,
+ customDomain: page.customDomain,
+ });
- for (const maintenance of page.maintenances) {
- const maintenanceUrl = `${baseUrl}/events/maintenance/${maintenance.id}`;
- feed.addItem({
- id: maintenanceUrl,
- title: `Maintenance - ${maintenance.title}`,
- link: maintenanceUrl,
- description: maintenance.message,
- date: maintenance.updatedAt ?? maintenance.createdAt ?? new Date(),
+ const feed = new Feed({
+ id: `${baseUrl}/feed/${type}`,
+ title: page.title,
+ description: page.description,
+ generator: "OpenStatus - Status Page Updates",
+ feedLinks: {
+ rss: `${baseUrl}/feed/rss`,
+ atom: `${baseUrl}/feed/atom`,
+ },
+ link: baseUrl,
+ author: {
+ name: page.title,
+ email:
+ page.contactUrl?.startsWith("mailto:") && page.contactUrl !== null
+ ? page.contactUrl.slice(7)
+ : undefined,
+ link: page.homepageUrl || baseUrl,
+ },
+ copyright: `Copyright ${new Date()
+ .getFullYear()
+ .toString()} openstatus.dev`,
+ language: "en-US",
+ updated: new Date(),
+ ttl: 60,
});
- }
- for (const statusReport of page.statusReports) {
- const statusReportUrl = `${baseUrl}/events/report/${statusReport.id}`;
- const status = STATUS_LABELS[statusReport.status];
- const statusReportUpdates = statusReport.statusReportUpdates
- .map((update) => {
- const updateStatus = STATUS_LABELS[update.status];
- return `${updateStatus}: ${update.message}.`;
- })
- .join("\n\n");
+ for (const maintenance of page.maintenances ?? []) {
+ const maintenanceUrl = `${baseUrl}/events/maintenance/${maintenance.id}`;
+ feed.addItem({
+ id: maintenanceUrl,
+ title: `Maintenance - ${maintenance.title}`,
+ link: maintenanceUrl,
+ description: maintenance.message,
+ date: maintenance.updatedAt ?? maintenance.createdAt ?? new Date(),
+ });
+ }
- feed.addItem({
- id: statusReportUrl,
- title: `${status} - ${statusReport.title}`,
- link: statusReportUrl,
- description: statusReportUpdates,
- date: statusReport.updatedAt ?? statusReport.createdAt ?? new Date(),
- });
- }
+ for (const statusReport of page.statusReports ?? []) {
+ const statusReportUrl = `${baseUrl}/events/report/${statusReport.id}`;
+ const status = STATUS_LABELS[statusReport.status] ?? statusReport.status;
+ const statusReportUpdates = (statusReport.statusReportUpdates ?? [])
+ .map((update) => {
+ const updateStatus = STATUS_LABELS[update.status] ?? update.status;
+ return `${updateStatus}: ${update.message}.`;
+ })
+ .join("\n\n");
+
+ feed.addItem({
+ id: statusReportUrl,
+ title: `${status} - ${statusReport.title}`,
+ link: statusReportUrl,
+ description: statusReportUpdates,
+ date: statusReport.updatedAt ?? statusReport.createdAt ?? new Date(),
+ });
+ }
- feed.items.sort(
- (a, b) => (a.date as Date).getTime() - (b.date as Date).getTime(),
- );
+ feed.items.sort((a, b) => a.date.getTime() - b.date.getTime());
- const res = type === "atom" ? feed.atom1() : feed.rss2();
+ const res = type === "atom" ? feed.atom1() : feed.rss2();
- return new Response(res, {
- headers: {
- "Content-Type": "application/xml; charset=utf-8",
- },
- });
+ return new Response(res, {
+ headers: {
+ "Content-Type": "application/xml; charset=utf-8",
+ },
+ });
+ } catch (error) {
+ console.error("Error generating feed:", error);
+ throw error;
+ }
}