mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +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 {
|
||||
return apply(func, undefined, args);
|
||||
} 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')));
|
||||
});
|
||||
|
||||
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) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user