From 2d3acccae2022a4605de7cf625af5055f1d1d2ff Mon Sep 17 00:00:00 2001 From: maciejpedzich Date: Wed, 6 Jul 2022 14:02:10 +0200 Subject: [PATCH] Ensure proper 404 Error handling --- pages/playlists/[playlistId].vue | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/pages/playlists/[playlistId].vue b/pages/playlists/[playlistId].vue index 709d334..797d865 100644 --- a/pages/playlists/[playlistId].vue +++ b/pages/playlists/[playlistId].vue @@ -20,16 +20,18 @@ const tabItems = [ { label: 'Show statistics', icon: 'pi pi-chart-bar', - to: `./statistics` + to: `./stats` } ]; -const { error, data } = await useFetch( +const { error, data: playlist } = await useFetch< + Playlist & { notFound?: true } +>( () => - `https://raw.githubusercontent.com/mackorone/spotify-playlist-archive/master/playlists/pretty/${playlistId}.json`, + `https://raw.githubusercontent.com/mackorone/spotify-playlist-archive/main/playlists/pretty/${playlistId}.json`, { parseResponse: (body) => - body.includes('404') ? { notFound: true } : JSON.parse(body), + body === '404: Not Found' ? { notFound: true } : JSON.parse(body), key: `playlist-${playlistId}` } ); @@ -47,20 +49,20 @@ const isNotFoundError = computed( Something went wrong while fetching playlist's data

-