diff --git a/src/layouts/PlaylistPageTab.astro b/src/layouts/PlaylistPageTab.astro index 816ec11..8774904 100644 --- a/src/layouts/PlaylistPageTab.astro +++ b/src/layouts/PlaylistPageTab.astro @@ -7,9 +7,11 @@ interface Props { playlist: PlaylistSnapshot | null; title: string; description: string; + errorOccurred: boolean; } -const { playlist, title, description } = Astro.props as Props; +const { playlistId } = Astro.params; +const { playlist, title, description, errorOccurred } = Astro.props as Props; --- @@ -20,7 +22,7 @@ const { playlist, title, description } = Astro.props as Props; ]} > { - playlist ? ( + !errorOccurred && playlist ? (

{title} @@ -35,7 +37,7 @@ const { playlist, title, description } = Astro.props as Props;

- + Browse snapshots diff --git a/src/utils/getPlaylistLayoutProps.ts b/src/utils/getPlaylistLayoutProps.ts index a844e87..f578894 100644 --- a/src/utils/getPlaylistLayoutProps.ts +++ b/src/utils/getPlaylistLayoutProps.ts @@ -9,13 +9,16 @@ export async function getPlaylistLayoutProps(Astro: Readonly) { let playlist: PlaylistSnapshot | null = null; let title = ''; let description = ''; + let errorOccurred = false; try { const githubResponse = await fetch( `https://raw.githubusercontent.com/mackorone/spotify-playlist-archive/main/playlists/pretty/${playlistId}.json` ); - if (!githubResponse.ok) throw new Error(githubResponse.status.toString()); + if (!githubResponse.ok) { + throw new Error(githubResponse.status.toString()); + } playlist = (await githubResponse.json()) as PlaylistSnapshot; description = decode(playlist.description, { level: 'html5' }); @@ -27,6 +30,7 @@ export async function getPlaylistLayoutProps(Astro: Readonly) { } catch (error) { const isNotFoundError = (error as Error).message === '404'; + errorOccurred = true; title = 'Error'; description = isNotFoundError ? "This playlist hasn't been archived yet." @@ -36,5 +40,5 @@ export async function getPlaylistLayoutProps(Astro: Readonly) { Astro.response.statusText = description; } - return { playlist, title, description }; + return { playlist, title, description, errorOccurred }; }