Skip to content

Commit bc92c37

Browse files
committed
Cleanup
1 parent e114fbd commit bc92c37

File tree

2 files changed

+30
-50
lines changed

2 files changed

+30
-50
lines changed

lib/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ exports.Boom = class Boom extends Error {
119119
}
120120

121121
static {
122-
Object.defineProperty(this.prototype, 'name', { value: 'Boom', writable: true, configurable: true });
123-
Object.defineProperty(this.prototype, 'isBoom', { value: true, writable: true, configurable: true });
122+
Object.defineProperties(this.prototype, {
123+
name: { value: 'Boom', writable: true, configurable: true },
124+
isBoom: { value: true, writable: true, configurable: true }
125+
});
124126
}
125127
};
126128

@@ -407,7 +409,5 @@ exports.gatewayTimeout = internals.statusError(504, internals.serverError);
407409

408410
exports.badImplementation = internals.statusError(500, (message, data) => {
409411

410-
const res = internals.serverError(message, data);
411-
res.push({ isDeveloperError: true });
412-
return res;
412+
return [...internals.serverError(message, data), { isDeveloperError: true }];
413413
});

test/index.js

+25-45
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,17 @@ describe('Boom', () => {
425425
});
426426
});
427427

428+
const utilities = ['badRequest', 'unauthorized', 'forbidden', 'notFound', 'methodNotAllowed',
429+
'notAcceptable', 'proxyAuthRequired', 'clientTimeout', 'conflict',
430+
'resourceGone', 'lengthRequired', 'preconditionFailed', 'entityTooLarge',
431+
'uriTooLong', 'unsupportedMediaType', 'rangeNotSatisfiable', 'expectationFailed',
432+
'badData', 'preconditionRequired', 'tooManyRequests',
433+
434+
// 500s
435+
'internal', 'notImplemented', 'badGateway', 'serverUnavailable',
436+
'gatewayTimeout', 'badImplementation'
437+
];
438+
428439
describe('badRequest()', () => {
429440

430441
it('returns a 400 error statusCode', () => {
@@ -1055,25 +1066,22 @@ describe('Boom', () => {
10551066
}
10561067
});
10571068
});
1058-
});
10591069

1060-
describe('stack trace', () => {
1070+
it('uses data with Error as cause', () => {
10611071

1062-
const helpers = ['badRequest', 'unauthorized', 'forbidden', 'notFound', 'methodNotAllowed',
1063-
'notAcceptable', 'proxyAuthRequired', 'clientTimeout', 'conflict',
1064-
'resourceGone', 'lengthRequired', 'preconditionFailed', 'entityTooLarge',
1065-
'uriTooLong', 'unsupportedMediaType', 'rangeNotSatisfiable', 'expectationFailed',
1066-
'badData', 'preconditionRequired', 'tooManyRequests',
1072+
const insideErr = new Error('inside');
1073+
const err = Boom.badImplementation('my message', insideErr);
1074+
expect(err.data).to.not.exist();
1075+
expect(err.cause).to.shallow.equal(insideErr);
1076+
});
1077+
});
10671078

1068-
// 500s
1069-
'internal', 'notImplemented', 'badGateway', 'serverUnavailable',
1070-
'gatewayTimeout', 'badImplementation'
1071-
];
1079+
describe('stack trace', () => {
10721080

10731081
it('should omit lib', () => {
10741082

1075-
for (const helper of helpers) {
1076-
const err = Boom[helper]();
1083+
for (const name of utilities) {
1084+
const err = Boom[name]();
10771085
expect(err.stack).to.not.match(/(\/|\\)lib(\/|\\)index\.js/);
10781086
}
10791087
});
@@ -1082,10 +1090,10 @@ describe('Boom', () => {
10821090

10831091
const captureStackTrace = Error.captureStackTrace;
10841092

1085-
for (const helper of helpers) {
1093+
for (const name of utilities) {
10861094
try {
10871095
Error.captureStackTrace = undefined;
1088-
var err = Boom[helper]();
1096+
var err = Boom[name]();
10891097
}
10901098
finally {
10911099
Error.captureStackTrace = captureStackTrace;
@@ -1098,35 +1106,7 @@ describe('Boom', () => {
10981106

10991107
describe('method with error object instead of message', () => {
11001108

1101-
[
1102-
'badRequest',
1103-
'unauthorized',
1104-
'forbidden',
1105-
'notFound',
1106-
'methodNotAllowed',
1107-
'notAcceptable',
1108-
'proxyAuthRequired',
1109-
'clientTimeout',
1110-
'conflict',
1111-
'resourceGone',
1112-
'lengthRequired',
1113-
'preconditionFailed',
1114-
'entityTooLarge',
1115-
'uriTooLong',
1116-
'unsupportedMediaType',
1117-
'rangeNotSatisfiable',
1118-
'expectationFailed',
1119-
'badData',
1120-
'preconditionRequired',
1121-
'tooManyRequests',
1122-
'internal',
1123-
'notImplemented',
1124-
'badGateway',
1125-
'serverUnavailable',
1126-
'gatewayTimeout',
1127-
'badImplementation'
1128-
].forEach((name) => {
1129-
1109+
for (const name of utilities) {
11301110
it(`uses stringified error as message`, () => {
11311111

11321112
const error = new Error('An example mongoose validation error');
@@ -1135,7 +1115,7 @@ describe('Boom', () => {
11351115
expect(err.cause).to.not.exist();
11361116
expect(err.message).to.equal(error.toString());
11371117
});
1138-
});
1118+
}
11391119
});
11401120

11411121
describe('reformat()', () => {

0 commit comments

Comments
 (0)