Skip to content

Commit 6560c66

Browse files
committed
fix: fix error being catchable with bad video id
closes #121 (again)
1 parent 3dcf7fb commit 6560c66

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/info.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ for (let funcName of ['getBasicInfo', 'getInfo']) {
470470
* @returns {Promise<Object>}
471471
*/
472472
const func = exports[funcName];
473-
exports[funcName] = (link, options = {}) => {
473+
exports[funcName] = async(link, options = {}) => {
474474
utils.checkForUpdates();
475-
let id = urlUtils.getVideoID(link);
475+
let id = await urlUtils.getVideoID(link);
476476
const key = [funcName, id, options.lang].join('-');
477477
return exports.cache.getOrSet(key, () => func(id, options));
478478
};

test/basic-info-test.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,22 @@ describe('ytdl.getBasicInfo()', () => {
452452
});
453453

454454
describe('With a bad video ID', () => {
455-
it('Returns an error', () => {
455+
it('Throws a catchable error', async() => {
456456
const id = 'bad';
457-
assert.throws(() => {
458-
ytdl.getBasicInfo(id);
459-
}, /No video id found: bad/);
457+
try {
458+
await ytdl.getBasicInfo(id);
459+
} catch (err) {
460+
assert.ok(/No video id found/.test(err.message));
461+
return;
462+
}
463+
throw Error('should not get here');
464+
});
465+
it('Promise is rejected with caught error', done => {
466+
const id = 'https://website.com';
467+
ytdl.getBasicInfo(id).catch(err => {
468+
assert.ok(/Not a YouTube domain/.test(err.message));
469+
done();
470+
});
460471
});
461472
});
462473

0 commit comments

Comments
 (0)