diff --git a/index.js b/index.js index ab2d294..8393646 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,11 @@ module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => { const timer = setTimeout(() => { if (typeof fallback === 'function') { - resolve(fallback()); + try { + resolve(fallback()); + } catch (err) { + reject(err); + } return; } diff --git a/test.js b/test.js index 8aa3879..b54cac1 100644 --- a/test.js +++ b/test.js @@ -30,6 +30,9 @@ test('fallback argument', async t => { await t.throws(m(delay(200), 50, 'rainbow'), 'rainbow'); await t.throws(m(delay(200), 50, new RangeError('cake')), RangeError); await t.throws(m(delay(200), 50, () => Promise.reject(fixtureErr)), fixtureErr.message); + await t.throws(m(delay(200), 50, () => { + throw new RangeError('cake'); + }), RangeError); }); test('calls `.cancel()` on promise when it exists', async t => {