mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 01:40:21 +03:00
✨ small error improvements
no issue - in Ignition we have added keeping the original stack, i copied it over - i would like to use Ignition in Ghost asap to avoid having inconsistencies - added support for options.err is a string - extend tests
This commit is contained in:
parent
e3d6e02aed
commit
d7c8da7ee8
@ -42,11 +42,28 @@ function GhostError(options) {
|
|||||||
// error to inherit from, override!
|
// error to inherit from, override!
|
||||||
// nested objects are getting copied over in one piece (can be changed, but not needed right now)
|
// nested objects are getting copied over in one piece (can be changed, but not needed right now)
|
||||||
if (options.err) {
|
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) {
|
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) {
|
if (['errorType', 'name', 'statusCode'].indexOf(property) !== -1) {
|
||||||
return;
|
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];
|
self[property] = options.err[property] || self[property];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,5 +67,13 @@ describe('Errors', function () {
|
|||||||
ghostError.message.should.eql(someError.message);
|
ghostError.message.should.eql(someError.message);
|
||||||
ghostError.context.should.eql('context');
|
ghostError.context.should.eql('context');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('error is string', function () {
|
||||||
|
var ghostError = new errors.GhostError({
|
||||||
|
err: 'string'
|
||||||
|
});
|
||||||
|
|
||||||
|
ghostError.message.should.eql('string');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user