From 33bff672cf5c61892f9115829cce30ee26234542 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Sun, 27 Aug 2023 11:05:12 -0700 Subject: [PATCH] fix: only look up a genre if we get an mbid --- netlify/edge-functions/now-playing.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/netlify/edge-functions/now-playing.js b/netlify/edge-functions/now-playing.js index 0e20af7c..d3789364 100644 --- a/netlify/edge-functions/now-playing.js +++ b/netlify/edge-functions/now-playing.js @@ -42,12 +42,17 @@ export default async () => { }).catch() const trackData = await trackRes.json() const track = trackData['recenttracks']['track'][0] - const genreUrl = `https://musicbrainz.org/ws/2/artist/${track['artist']['mbid']}?inc=aliases+genres&fmt=json` - const genreRes = await fetch(genreUrl, { - type: 'json', - }).catch() - const genreData = await genreRes.json() - const genre = genreData.genres.sort((a, b) => b.count - a.count)[0]['name'] + const mbid = track['artist']['mbid'] + let genre = '' + + if (mbid && mbid !== '') { + const genreUrl = `https://musicbrainz.org/ws/2/artist/${mbid}?inc=aliases+genres&fmt=json` + const genreRes = await fetch(genreUrl, { + type: 'json', + }).catch() + const genreData = await genreRes.json() + genre = genreData.genres.sort((a, b) => b.count - a.count)[0]['name'] + } return Response.json({ artist: track['artist']['#text'],