From 42554714f2a0fd85e573ae2836c9509d9ac123d5 Mon Sep 17 00:00:00 2001 From: Tomas Hubelbauer Date: Mon, 3 Jun 2024 21:34:06 +0200 Subject: [PATCH] Improve lyrics download error reporting messages Much nicer this way. --- index.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 674ea1a..628ccc9 100644 --- a/index.js +++ b/index.js @@ -163,23 +163,31 @@ electron.app.on('ready', async () => { console.log(`Downloaded ${lyrics.syncType === 'LINE_SYNCED' ? 'synchronized' : 'unsynchronized'} ${artist} - ${song}`); } else { - lyrics = { artist, song, error: response.status + ' ' + response.statusText }; + lyrics = { artist, song, error: await response.text() }; + + switch (response.status) { + // Force the user to re-authenticate if the token is invalid + case 401: { + // Reset the field while re-authenticating to prevent multiple prompts + authorization = undefined; + authorization = await promptAuthorization(true); + + // Reset the lyrics so they are re-tried with the new token + lyrics = undefined; + break; + } - // Force the user to re-authenticate if the token is invalid - if (response.status === 401) { - // Reset the field while re-authenticating to prevent multiple prompts - authorization = undefined; - authorization = await promptAuthorization(true); + case 404: { + console.log(`No lyrics found for ${artist} - ${song}`); + break; + } - // Reset the lyrics so they are re-tried with the new token - lyrics = undefined; + default: { + console.log(`Failed to download ${artist} - ${song}: ${response.status} ${response.statusText} ${lyrics.error}`); + } } } } - - if (lyrics.error) { - console.log(`Lyrics error for ${artist} - ${song}: ${lyrics.error}`); - } } try {