From 64b879ede279d2392274f583090c0cd7f9aa2e0e Mon Sep 17 00:00:00 2001 From: DerLev Date: Mon, 22 Apr 2024 15:21:37 +0200 Subject: [PATCH] fixing error in Spotify API song search: filtering out nulled items --- functions/src/helpers/spotifyConverters.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions/src/helpers/spotifyConverters.ts b/functions/src/helpers/spotifyConverters.ts index d5e026d..8899b6f 100644 --- a/functions/src/helpers/spotifyConverters.ts +++ b/functions/src/helpers/spotifyConverters.ts @@ -90,12 +90,15 @@ export const convertStationPlaylist = async ( ); } + const filterNulledItems = result.tracks.items + .filter((item) => item !== null); + const songsCollection = db.collection("songs") .withConverter(firestoreConverter()); /* Retry track search -> get track by Spotify URI */ const trackByURI = await songsCollection - .where("spotifyTrackUri", "==", result.tracks.items[0].uri) + .where("spotifyTrackUri", "==", filterNulledItems[0].uri) .limit(1).get(); /* If track was found... */