Ensure _.attempt preserves custom errors.

This commit is contained in:
Ivan Tanev
2016-01-30 02:52:36 +02:00
committed by John-David Dalton
parent ac9b0bfc1b
commit 13659e87cb
2 changed files with 15 additions and 1 deletions

View File

@@ -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);
}
});

View File

@@ -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);