diff --git a/src/components/InsidePostHog/Anniversaries.tsx b/src/components/InsidePostHog/Anniversaries.tsx index e65ee814cead..12bbd03a0de5 100644 --- a/src/components/InsidePostHog/Anniversaries.tsx +++ b/src/components/InsidePostHog/Anniversaries.tsx @@ -29,7 +29,12 @@ export default function Anniversaries() { { encodeValuesOnly: true } ) fetch(`${process.env.GATSBY_SQUEAK_API_HOST}/api/profiles?${query}`) - .then((res) => res.json()) + .then((res) => { + if (!res.ok) { + throw new Error(`Failed to fetch profiles: ${res.status}`) + } + return res.json() + }) .then(({ data }) => { const teamMembers = data.filter((teamMember) => { const { @@ -45,6 +50,10 @@ export default function Anniversaries() { setTeamMembers(teamMembers) setLoading(false) }) + .catch(() => { + setTeamMembers([]) + setLoading(false) + }) }, []) return loading ? ( diff --git a/src/components/InsidePostHog/Newbies.tsx b/src/components/InsidePostHog/Newbies.tsx index a4b1676542f1..245b1ac9f644 100644 --- a/src/components/InsidePostHog/Newbies.tsx +++ b/src/components/InsidePostHog/Newbies.tsx @@ -29,11 +29,20 @@ export default function Newbies() { { encodeValuesOnly: true } ) fetch(`${process.env.GATSBY_SQUEAK_API_HOST}/api/profiles?${query}`) - .then((res) => res.json()) + .then((res) => { + if (!res.ok) { + throw new Error(`Failed to fetch profiles: ${res.status}`) + } + return res.json() + }) .then(({ data }) => { setNewbies(data) setLoading(false) }) + .catch(() => { + setNewbies([]) + setLoading(false) + }) }, []) return loading ? ( diff --git a/src/components/InsidePostHog/WIP.tsx b/src/components/InsidePostHog/WIP.tsx index 65ceccf4d64c..0418d1971039 100644 --- a/src/components/InsidePostHog/WIP.tsx +++ b/src/components/InsidePostHog/WIP.tsx @@ -28,7 +28,12 @@ const getRecentUpdate = async () => { }, { encodeValuesOnly: true } )}` - ).then((res) => res.json()) + ).then((res) => { + if (!res.ok) { + throw new Error(`Failed to fetch team updates: ${res.status}`) + } + return res.json() + }) return data } @@ -36,24 +41,27 @@ export default function WIP() { const [recentUpdate, setRecentUpdate] = useState() const [loading, setLoading] = useState(true) useEffect(() => { - getRecentUpdate().then((recentUpdate) => setRecentUpdate(recentUpdate?.[0])) + getRecentUpdate() + .then((recentUpdate) => setRecentUpdate(recentUpdate?.[0])) + .catch(() => setRecentUpdate(undefined)) + .finally(() => setLoading(false)) }, []) - useEffect(() => { - if (recentUpdate) { - setLoading(false) - } - }, [recentUpdate]) - const team = recentUpdate?.attributes?.team?.data?.attributes const profile = recentUpdate?.attributes?.question?.data?.attributes?.profile?.data const name = [profile?.attributes?.firstName, profile?.attributes?.lastName].filter(Boolean).join(' ') const avatarURL = profile?.attributes?.avatar?.data?.attributes?.formats?.thumbnail?.url const roadmap = recentUpdate?.attributes?.roadmap?.data - return loading ? ( - - ) : ( + if (loading) { + return + } + + if (!recentUpdate) { + return null + } + + return (

WIP

Updates on things we're working on right now