Catch error thrown in fallback (#8)
This commit is contained in:
parent
63a486a0f2
commit
7fc1cb3dd2
4
index.js
4
index.js
|
@ -15,7 +15,11 @@ module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
|
|||
|
||||
const timer = setTimeout(() => {
|
||||
if (typeof fallback === 'function') {
|
||||
try {
|
||||
resolve(fallback());
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
3
test.js
3
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 => {
|
||||
|
|
Loading…
Reference in New Issue