Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Gracefully handle content API errors

Tim Wilson2531cb66b5e6
diff --git a/apps/web/lib/fetchers/get-content-api.ts b/apps/web/lib/fetchers/get-content-api.ts
index 6c8c66e001..f7dc4017f5 100644
--- a/apps/web/lib/fetchers/get-content-api.ts
+++ b/apps/web/lib/fetchers/get-content-api.ts
@@ -1,9 +1,24 @@
+import { HelpArticle } from "@/ui/layout/help";
+import { NewsArticle } from "@/ui/layout/sidebar/news";
import { cache } from "react";
-export const getContentAPI = cache(async () => {
- return await fetch("https://dub.co/api/content", {
- next: {
- revalidate: 60 * 60 * 24, // cache for 24 hours
- },
- }).then((res) => res.json());
+export const getContentAPI: () => Promise<{
+ allHelpArticles: HelpArticle[];
+ popularHelpArticles: HelpArticle[];
+ latestNewsArticles: NewsArticle[];
+}> = cache(async () => {
+ try {
+ return await fetch("https://dub.co/api/content", {
+ next: {
+ revalidate: 60 * 60 * 24, // cache for 24 hours
+ },
+ }).then((res) => res.json());
+ } catch (e) {
+ console.error("Failed to fetch content from dub.co/api/content", e);
+ return {
+ allHelpArticles: [],
+ popularHelpArticles: [],
+ latestNewsArticles: [],
+ };
+ }
});