From 20f12eb9bc93960e13403ebb33b234fd7af06e40 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 27 Dec 2024 21:08:13 +0000 Subject: [PATCH] Make aggregator failsafe --- src/lib/server/contentAgregator.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/server/contentAgregator.ts b/src/lib/server/contentAgregator.ts index 815ee91..642ba61 100644 --- a/src/lib/server/contentAgregator.ts +++ b/src/lib/server/contentAgregator.ts @@ -32,8 +32,17 @@ const compareContentDate = (a: Content, b: Content) => { export const aggregateContent = async () => { let content: Content[] = []; - content.push(...(await fetchInstagramContent())); - content.push(...(await fetchBlogPosts())); + try { + content.push(...(await fetchInstagramContent())); + } catch(e) { + console.error("Unable to fetch instagram content: ", e) + } + + try { + content.push(...(await fetchBlogPosts())); + } catch(e) { + console.error("Unable to fetch ghost content: ", e) + } content.sort(compareContentDate); @@ -62,6 +71,7 @@ export const fetchBlogPosts = async () => { throw 'Not Found'; } } catch (e) { + console.error(e) throw new Error('Failed to communicate with Ghost'); } @@ -95,6 +105,7 @@ export const fetchInstagramContent = async () => { ); if (!response.ok) { + console.error(response.status) throw new Error('Failed to communicate with Instagram'); }