From d03fbf7ad5ba1dc11634ea9d08fd7b2b2044ebbf Mon Sep 17 00:00:00 2001 From: Nayan Date: Tue, 3 Dec 2024 20:41:29 +0530 Subject: [PATCH] fix: api null response error --- src/constants/cleanUpData.js | 63 +++++++++++++++++++----------------- src/pages/Home/Home.jsx | 2 +- src/pages/Search/Search.jsx | 5 --- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/constants/cleanUpData.js b/src/constants/cleanUpData.js index fe85c4b..075f1c1 100644 --- a/src/constants/cleanUpData.js +++ b/src/constants/cleanUpData.js @@ -35,48 +35,51 @@ const LikedSongs = (userData) => { const album = (albumData) => { if (albumData && albumData.total > 0) { return albumData.items.map((obj) => { - return { - title: removeCharactersAfterSymbol(obj.album.name), - type: obj.album.type, - image: obj.album.images, - songs: obj.album.tracks.total, - id: obj.album.id, - href: obj.album.href, - items: null, - routePath: obj.album.type, - }; + if (obj != null) + return { + title: removeCharactersAfterSymbol(obj.album.name), + type: obj.album.type, + image: obj.album.images, + songs: obj.album.tracks.total, + id: obj.album.id, + href: obj.album.href, + items: null, + routePath: obj.album.type, + }; }); } }; const playlist = (playlistData) => { if (playlistData && playlistData.total > 0) { return playlistData.items.map((obj) => { - return { - title: removeCharactersAfterSymbol(obj.name), - type: obj.type, - image: obj.images, - songs: obj.tracks.total, - id: obj.id, - href: obj.href, - items: null, - routePath: obj.type, - }; + if (obj != null) + return { + title: removeCharactersAfterSymbol(obj.name), + type: obj.type, + image: obj.images, + songs: obj.tracks.total, + id: obj.id, + href: obj.href, + items: null, + routePath: obj.type, + }; }); } }; const artists = (artistsData) => { if (artistsData && artistsData.artists.total > 0) { return artistsData.artists.items.map((obj) => { - return { - title: removeCharactersAfterSymbol(obj.name), - type: obj.type, - image: obj.images, - songs: null, - id: obj.id, - href: obj.href, - items: null, - routePath: obj.type, - }; + if (obj != null) + return { + title: removeCharactersAfterSymbol(obj.name), + type: obj.type, + image: obj.images, + songs: null, + id: obj.id, + href: obj.href, + items: null, + routePath: obj.type, + }; }); } }; diff --git a/src/pages/Home/Home.jsx b/src/pages/Home/Home.jsx index 94b1c8e..ce0ed3b 100644 --- a/src/pages/Home/Home.jsx +++ b/src/pages/Home/Home.jsx @@ -26,7 +26,7 @@ function HomeSection() { // fetchData(`${Several_Albums}{id}`), // // fetchData(`${Top_Items}`), // fetchData(`${Single_Artists}{id}`), - fetchData(`${Featured_Playlist}`), + // fetchData(`${Featured_Playlist}`), // fetchData(`${Several_Tracks}{id}`), // // fetchData(`${Artists_TopTracks}`), fetchData(`${New_Release}`), diff --git a/src/pages/Search/Search.jsx b/src/pages/Search/Search.jsx index a80fe92..409c2bf 100644 --- a/src/pages/Search/Search.jsx +++ b/src/pages/Search/Search.jsx @@ -24,11 +24,6 @@ function Search() { console.log(err); }); }; - - useEffect(() => { - console.log(searchCategory); - }, [searchCategory]); - useEffect(() => { if (!searchCategory) { fetchData(`${Several_Category}?limit=50`)