catch errors in downloadSong()

This commit is contained in:
Araxeus
2023-03-15 20:29:12 +02:00
parent b652a011a5
commit 51871a3fec

View File

@ -59,7 +59,7 @@ const sendError = (error) => {
buttons: ["OK"],
title: "Error in download!",
message: "Argh! Apologies, download failed…",
detail: error.toString(),
detail: `${error.toString()} ${error.cause ? `\n\n${error.cause.toString()}` : ''}`,
});
};
@ -89,6 +89,19 @@ async function downloadSong(
playlistFolder = undefined,
trackId = undefined,
increasePlaylistProgress = () => {},
) {
try {
await downloadSongUnsafe(url, playlistFolder, trackId, increasePlaylistProgress);
} catch (error) {
sendError(error);
}
}
async function downloadSongUnsafe(
url,
playlistFolder = undefined,
trackId = undefined,
increasePlaylistProgress = () => {},
) {
const sendFeedback = (message, progress) => {
if (!playlistFolder) {