Skip to content

Commit

Permalink
Improve lyrics download error reporting messages
Browse files Browse the repository at this point in the history
Much nicer this way.
  • Loading branch information
TomasHubelbauer committed Jun 3, 2024
1 parent 01c967a commit 4255471
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4255471

Please sign in to comment.