From 93c317393f0566bd730bf050ce799d5fc8780f4f Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Tue, 28 Nov 2023 08:39:47 -0500 Subject: [PATCH] fix: switch try catch --- apps/cast/src/pages/slideshow.tsx | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/apps/cast/src/pages/slideshow.tsx b/apps/cast/src/pages/slideshow.tsx index be65ab431..32fca6735 100644 --- a/apps/cast/src/pages/slideshow.tsx +++ b/apps/cast/src/pages/slideshow.tsx @@ -26,18 +26,24 @@ export default function Slideshow() { >({}); const init = async () => { - // get requested collection id from localStorage - const requestedCollectionID = - window.localStorage.getItem('targetCollectionId'); + try { + // get requested collection id from localStorage + const requestedCollectionID = + window.localStorage.getItem('targetCollectionId'); - const collection = await getCollection(Number(requestedCollectionID)); - - const files = await syncFiles('normal', [collection], () => {}); - - if (requestedCollectionID) { - setCollectionFiles( - files.filter((file) => isFileEligibleForCast(file)) + const collection = await getCollection( + Number(requestedCollectionID) ); + + const files = await syncFiles('normal', [collection], () => {}); + + if (requestedCollectionID) { + setCollectionFiles( + files.filter((file) => isFileEligibleForCast(file)) + ); + } + } catch { + router.push('/'); } }; @@ -70,11 +76,7 @@ export default function Slideshow() { const router = useRouter(); useEffect(() => { - try { - init(); - } catch (e) { - router.push('/'); - } + init(); }, []); useEffect(() => {