From 987f50604a0163f9a07091ce787995c6f6fddb75 Mon Sep 17 00:00:00 2001 From: LuanRT Date: Sun, 1 Oct 2023 23:31:05 -0300 Subject: [PATCH] fix(Playlist): Throw a more helpful error when parsing empty responses --- src/parser/youtube/Playlist.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/parser/youtube/Playlist.ts b/src/parser/youtube/Playlist.ts index 5496fa4d..f4b58d62 100644 --- a/src/parser/youtube/Playlist.ts +++ b/src/parser/youtube/Playlist.ts @@ -9,6 +9,7 @@ import PlaylistSidebarPrimaryInfo from '../classes/PlaylistSidebarPrimaryInfo.js import PlaylistSidebarSecondaryInfo from '../classes/PlaylistSidebarSecondaryInfo.js'; import PlaylistVideoThumbnail from '../classes/PlaylistVideoThumbnail.js'; import VideoOwner from '../classes/VideoOwner.js'; +import Alert from '../classes/Alert.js'; import { InnertubeError } from '../../utils/Utils.js'; import type { ObservedArray } from '../helpers.js'; @@ -17,7 +18,7 @@ import type Actions from '../../core/Actions.js'; import type { ApiResponse } from '../../core/Actions.js'; import type { IBrowseResponse } from '../types/ParsedResponse.js'; -class Playlist extends Feed { +export default class Playlist extends Feed { info; menu; endpoint?: NavigationEndpoint; @@ -29,9 +30,13 @@ class Playlist extends Feed { const header = this.memo.getType(PlaylistHeader).first(); const primary_info = this.memo.getType(PlaylistSidebarPrimaryInfo).first(); const secondary_info = this.memo.getType(PlaylistSidebarSecondaryInfo).first(); + const alert = this.page.alerts?.firstOfType(Alert); - if (!primary_info && !secondary_info) - throw new InnertubeError('This playlist does not exist'); + if (alert && alert.alert_type === 'ERROR') + throw new InnertubeError(alert.text.toString(), alert); + + if (!primary_info && !secondary_info && Object.keys(this.page).length === 0) + throw new InnertubeError('Got empty continuation response. This is likely the end of the playlist.'); this.info = { ...this.page.metadata?.item().as(PlaylistMetadata), @@ -69,6 +74,4 @@ class Playlist extends Feed { throw new InnertubeError('Could not get continuation data'); return new Playlist(this.actions, page, true); } -} - -export default Playlist; \ No newline at end of file +} \ No newline at end of file