11import httpErrors from 'http-errors' ;
2- import Client , { PlaylistItemResource , PlaylistResource } from './Client' ;
2+ import Client , { type PlaylistItemResource , type PlaylistResource } from './Client' ;
33import { getBestThumbnail , getPlaylistID , getVideos , type UwMedia } from './util' ;
44
55const { BadRequest, NotFound } = httpErrors ;
@@ -105,7 +105,11 @@ export default class YouTubeImport {
105105 id : playlistID ,
106106 maxResults : 1 ,
107107 } ) ;
108- return data . items [ 0 ] ;
108+ const [ playlist ] = data . items ;
109+ if ( playlist == null ) {
110+ throw new NotFound ( 'Playlist not found.' ) ;
111+ }
112+ return playlist ;
109113 }
110114
111115 async getImportablePlaylist ( url : string ) : Promise < {
@@ -149,11 +153,11 @@ export default class YouTubeImport {
149153 } ;
150154 let idOptions ;
151155 if ( match ) {
152- idOptions = { id : match [ 1 ] } ;
156+ idOptions = { id : match [ 1 ] ! } ;
153157 } else {
154158 match = url . match ( rxUserUrl ) ;
155159 if ( match ) {
156- idOptions = { forUsername : match [ 1 ] } ;
160+ idOptions = { forUsername : match [ 1 ] ! } ;
157161 } else {
158162 throw new BadRequest (
159163 'Invalid channel URL. Please provide a direct link to the channel or '
@@ -173,7 +177,7 @@ export default class YouTubeImport {
173177 ) ;
174178 }
175179
176- const channel = data . items [ 0 ] ;
180+ const channel = data . items [ 0 ] ! ;
177181 return {
178182 id : channel . id ,
179183 title : channel . snippet . title ,
0 commit comments