From 516eb2557f41d7fcffbce101f51c0d08a59a919d Mon Sep 17 00:00:00 2001
From: RemixDev <RemixDev64@gmail.com>
Date: Sat, 28 May 2022 15:49:26 +0200
Subject: [PATCH] Fix crash with wrong spotify username

---
 server/src/routes/api/get/getUserSpotifyPlaylists.ts | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/server/src/routes/api/get/getUserSpotifyPlaylists.ts b/server/src/routes/api/get/getUserSpotifyPlaylists.ts
index f6f3178..04057be 100644
--- a/server/src/routes/api/get/getUserSpotifyPlaylists.ts
+++ b/server/src/routes/api/get/getUserSpotifyPlaylists.ts
@@ -10,7 +10,13 @@ const handler: ApiHandler['handler'] = async (req, res) => {
 		const sp = deemix.plugins.spotify.sp
 		const username = req.query.spotifyUser
 		data = []
-		let playlists = await sp.getUserPlaylists(username)
+		let playlists
+		try {
+			playlists = await sp.getUserPlaylists(username)
+		} catch (e) {
+			res.send({ error: 'wrongSpotifyUsername', username })
+			return
+		}
 		playlists = playlists.body
 		let playlistList = playlists.items
 		while (playlists.next) {