Improve error messages on unplayable videos

This commit is contained in:
Brahim Hadriche committed 2024-10-19 11:59:27 -04:00
1 parent 956249393d
commit 8252a102b5
3 files changed
+45 -2

No files matched your search

+14 -1
View File
@@ -90,7 +90,20 @@ export class YoutubeJs {
console.log('[YTJS] info:', info);
if (info.playability_status.status !== 'OK') {
throw new Error(`Video not available: ${info.playability_status.reason}`);
let errorMessage = "";
if (info.playability_status.reason) {
errorMessage = info.playability_status.reason;
}
if (info.playability_status.error_screen) {
if (info.playability_status.error_screen.hasKey('subreason')) {
const subreason = info.playability_status.error_screen.subreason;
if (subreason?.text && typeof subreason.text === 'string') {
errorMessage += `\n` + subreason.text;
}
}
}
throw new Error(errorMessage);
}
// Populate a video object that is similar to Invidious format.
+2
View File
@@ -115,6 +115,8 @@
videoStartAtTimestamp = timestamp;
}
videoModal.show();
} catch (error) {
alert(error);
} finally {
isLoading = false;
}