mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Merge pull request #7698 from kirrg001/1.0.0-dev/error-inheritance-improvement
✨ small error improvements
This commit is contained in:
commit
f69ec600c0
2 changed files with 25 additions and 0 deletions
|
@ -42,11 +42,28 @@ function GhostError(options) {
|
|||
// error to inherit from, override!
|
||||
// nested objects are getting copied over in one piece (can be changed, but not needed right now)
|
||||
if (options.err) {
|
||||
// it can happen that third party libs return errors as strings, yes really
|
||||
// we are creating an error stack from this line, but we need to ensure not loosing the original error message
|
||||
if (_.isString(options.err)) {
|
||||
options.err = new Error(options.err);
|
||||
}
|
||||
|
||||
Object.getOwnPropertyNames(options.err).forEach(function (property) {
|
||||
// original message is part of the stack, no need to pick it
|
||||
if (['errorType', 'name', 'statusCode'].indexOf(property) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'message' && !self[property]) {
|
||||
self[property] = options.err[property];
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'stack') {
|
||||
self[property] += '\n\n' + options.err[property];
|
||||
return;
|
||||
}
|
||||
|
||||
self[property] = options.err[property] || self[property];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -67,5 +67,13 @@ describe('Errors', function () {
|
|||
ghostError.message.should.eql(someError.message);
|
||||
ghostError.context.should.eql('context');
|
||||
});
|
||||
|
||||
it('error is string', function () {
|
||||
var ghostError = new errors.GhostError({
|
||||
err: 'string'
|
||||
});
|
||||
|
||||
ghostError.message.should.eql('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue