2018-06-02 21:48:23 +02:00
|
|
|
var should = require('should'),
|
2020-03-30 16:26:47 +01:00
|
|
|
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 () {
|
2017-12-11 22:47:46 +01:00
|
|
|
var 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 () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
var someError = new Error(), ghostError;
|
|
|
|
|
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 () {
|
2017-12-11 22:47:46 +01:00
|
|
|
var 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
|
|
|
});
|
|
|
|
});
|