2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const common = require('../../../../core/server/lib/common');
|
2016-10-10 19:30:30 +02:00
|
|
|
|
|
|
|
describe('Errors', function () {
|
2016-10-19 16:27:22 +02:00
|
|
|
it('Ensure we inherit from Error', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const ghostError = new common.errors.GhostError();
|
2016-10-19 16:27:22 +02:00
|
|
|
(ghostError instanceof Error).should.eql(true);
|
|
|
|
});
|
|
|
|
|
2016-10-10 19:30:30 +02:00
|
|
|
describe('Inherite from other error', function () {
|
|
|
|
it('default', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const someError = new Error();
|
|
|
|
let ghostError;
|
2016-10-10 19:30:30 +02:00
|
|
|
|
|
|
|
someError.message = 'test';
|
|
|
|
someError.context = 'test';
|
|
|
|
someError.help = 'test';
|
|
|
|
|
2017-12-11 22:47:46 +01:00
|
|
|
ghostError = new common.errors.GhostError({err: someError});
|
2017-01-23 12:04:01 +01:00
|
|
|
ghostError.stack.should.match(/Error: test/);
|
2016-10-10 19:30:30 +02:00
|
|
|
ghostError.context.should.eql(someError.context);
|
|
|
|
ghostError.help.should.eql(someError.help);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has nested object', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const someError = new Error();
|
|
|
|
let ghostError;
|
2016-10-10 19:30:30 +02:00
|
|
|
|
|
|
|
someError.obj = {
|
|
|
|
a: 'b'
|
|
|
|
};
|
|
|
|
|
2017-12-11 22:47:46 +01:00
|
|
|
ghostError = new common.errors.GhostError({
|
2016-10-10 19:30:30 +02:00
|
|
|
err: someError
|
|
|
|
});
|
|
|
|
|
|
|
|
ghostError.obj.should.eql(someError.obj);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with custom attribute', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const someError = new Error();
|
|
|
|
let ghostError;
|
2016-10-10 19:30:30 +02:00
|
|
|
|
|
|
|
someError.context = 'test';
|
|
|
|
|
2017-12-11 22:47:46 +01:00
|
|
|
ghostError = new common.errors.GhostError({
|
2016-10-10 19:30:30 +02:00
|
|
|
err: someError,
|
|
|
|
context: 'context'
|
|
|
|
});
|
|
|
|
|
|
|
|
ghostError.context.should.eql('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with custom attribute', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const someError = new Error();
|
|
|
|
let ghostError;
|
2016-10-10 19:30:30 +02:00
|
|
|
|
2017-12-11 22:47:46 +01:00
|
|
|
ghostError = new common.errors.GhostError({
|
2016-10-10 19:30:30 +02:00
|
|
|
err: someError,
|
2017-01-23 12:04:01 +01:00
|
|
|
message: 'test'
|
2016-10-10 19:30:30 +02:00
|
|
|
});
|
|
|
|
|
2017-01-23 12:04:01 +01:00
|
|
|
ghostError.message.should.eql('test');
|
2016-10-10 19:30:30 +02:00
|
|
|
});
|
2016-11-09 09:13:50 +01:00
|
|
|
|
|
|
|
it('error is string', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const ghostError = new common.errors.GhostError({
|
2016-11-09 09:13:50 +01:00
|
|
|
err: 'string'
|
|
|
|
});
|
|
|
|
|
2017-01-23 12:04:01 +01:00
|
|
|
ghostError.stack.should.match(/Error: string/);
|
2016-11-09 09:13:50 +01:00
|
|
|
});
|
2016-10-10 19:30:30 +02:00
|
|
|
});
|
|
|
|
});
|