mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Ensure _.attempt preserves custom errors.
This commit is contained in:
committed by
John-David Dalton
parent
ac9b0bfc1b
commit
13659e87cb
@@ -12926,7 +12926,7 @@
|
|||||||
try {
|
try {
|
||||||
return apply(func, undefined, args);
|
return apply(func, undefined, args);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return isError(e) ? e : new Error(e);
|
return isObject(e) ? e : new Error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
14
test/test.js
14
test/test.js
@@ -1482,6 +1482,20 @@
|
|||||||
assert.ok(lodashStable.isEqual(actual, Error('x')));
|
assert.ok(lodashStable.isEqual(actual, Error('x')));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should preserve custom errors', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
function CustomError(message) {
|
||||||
|
this.name = 'CustomError';
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomError.prototype = lodashStable.create(Error.prototype);
|
||||||
|
|
||||||
|
var actual = _.attempt(function() { throw new CustomError('x'); });
|
||||||
|
assert.ok(actual instanceof CustomError);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should work with an error object from another realm', function(assert) {
|
QUnit.test('should work with an error object from another realm', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user