Skip to content

Commit

Permalink
fix: fix error being catchable with bad video id
Browse files Browse the repository at this point in the history
closes #121 (again)
  • Loading branch information
fent committed Jan 2, 2021
1 parent 3dcf7fb commit 6560c66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/info.js
Expand Up @@ -470,9 +470,9 @@ for (let funcName of ['getBasicInfo', 'getInfo']) {
* @returns {Promise<Object>}
*/
const func = exports[funcName];
exports[funcName] = (link, options = {}) => {
exports[funcName] = async(link, options = {}) => {
utils.checkForUpdates();
let id = urlUtils.getVideoID(link);
let id = await urlUtils.getVideoID(link);
const key = [funcName, id, options.lang].join('-');
return exports.cache.getOrSet(key, () => func(id, options));
};
Expand Down
19 changes: 15 additions & 4 deletions test/basic-info-test.js
Expand Up @@ -452,11 +452,22 @@ describe('ytdl.getBasicInfo()', () => {
});

describe('With a bad video ID', () => {
it('Returns an error', () => {
it('Throws a catchable error', async() => {
const id = 'bad';
assert.throws(() => {
ytdl.getBasicInfo(id);
}, /No video id found: bad/);
try {
await ytdl.getBasicInfo(id);
} catch (err) {
assert.ok(/No video id found/.test(err.message));
return;
}
throw Error('should not get here');
});
it('Promise is rejected with caught error', done => {
const id = 'https://website.com';
ytdl.getBasicInfo(id).catch(err => {
assert.ok(/Not a YouTube domain/.test(err.message));
done();
});
});
});

Expand Down

0 comments on commit 6560c66

Please sign in to comment.