boom
Advanced tools
Comparing version 2.8.0 to 2.9.0
@@ -11,3 +11,2 @@ // Load modules | ||
exports.wrap = function (error, statusCode, message) { | ||
@@ -22,3 +21,9 @@ | ||
return internals.create(statusCode, message, data, exports.create); | ||
}; | ||
internals.create = function (statusCode, message, data, ctor) { | ||
var error = new Error(message ? message : undefined); // Avoids settings null message | ||
Error.captureStackTrace(error, ctor); // Filter the stack to our external API | ||
error.data = data || null; | ||
@@ -29,3 +34,2 @@ internals.initialize(error, statusCode); | ||
internals.initialize = function (error, statusCode, message) { | ||
@@ -84,3 +88,3 @@ | ||
return exports.create(400, message, data); | ||
return internals.create(400, message, data, exports.badRequest); | ||
}; | ||
@@ -91,3 +95,3 @@ | ||
var err = exports.create(401, message); | ||
var err = internals.create(401, message, undefined, exports.unauthorized); | ||
@@ -164,3 +168,3 @@ if (!scheme) { | ||
return exports.create(403, message, data); | ||
return internals.create(403, message, data, exports.forbidden); | ||
}; | ||
@@ -171,3 +175,3 @@ | ||
return exports.create(404, message, data); | ||
return internals.create(404, message, data, exports.notFound); | ||
}; | ||
@@ -178,3 +182,3 @@ | ||
return exports.create(405, message, data); | ||
return internals.create(405, message, data, exports.methodNotAllowed); | ||
}; | ||
@@ -185,3 +189,3 @@ | ||
return exports.create(406, message, data); | ||
return internals.create(406, message, data, exports.notAcceptable); | ||
}; | ||
@@ -192,3 +196,3 @@ | ||
return exports.create(407, message, data); | ||
return internals.create(407, message, data, exports.proxyAuthRequired); | ||
}; | ||
@@ -199,3 +203,3 @@ | ||
return exports.create(408, message, data); | ||
return internals.create(408, message, data, exports.clientTimeout); | ||
}; | ||
@@ -206,3 +210,3 @@ | ||
return exports.create(409, message, data); | ||
return internals.create(409, message, data, exports.conflict); | ||
}; | ||
@@ -213,3 +217,3 @@ | ||
return exports.create(410, message, data); | ||
return internals.create(410, message, data, exports.resourceGone); | ||
}; | ||
@@ -220,3 +224,3 @@ | ||
return exports.create(411, message, data); | ||
return internals.create(411, message, data, exports.lengthRequired); | ||
}; | ||
@@ -227,3 +231,3 @@ | ||
return exports.create(412, message, data); | ||
return internals.create(412, message, data, exports.preconditionFailed); | ||
}; | ||
@@ -234,3 +238,3 @@ | ||
return exports.create(413, message, data); | ||
return internals.create(413, message, data, exports.entityTooLarge); | ||
}; | ||
@@ -241,3 +245,3 @@ | ||
return exports.create(414, message, data); | ||
return internals.create(414, message, data, exports.uriTooLong); | ||
}; | ||
@@ -248,3 +252,3 @@ | ||
return exports.create(415, message, data); | ||
return internals.create(415, message, data, exports.unsupportedMediaType); | ||
}; | ||
@@ -255,3 +259,3 @@ | ||
return exports.create(416, message, data); | ||
return internals.create(416, message, data, exports.rangeNotSatisfiable); | ||
}; | ||
@@ -262,3 +266,3 @@ | ||
return exports.create(417, message, data); | ||
return internals.create(417, message, data, exports.expectationFailed); | ||
}; | ||
@@ -268,3 +272,3 @@ | ||
return exports.create(422, message, data); | ||
return internals.create(422, message, data, exports.badData); | ||
}; | ||
@@ -275,3 +279,3 @@ | ||
return exports.create(429, message, data); | ||
return internals.create(429, message, data, exports.tooManyRequests); | ||
}; | ||
@@ -284,5 +288,12 @@ | ||
var error = (data instanceof Error ? exports.wrap(data, statusCode, message) : exports.create(statusCode || 500, message)); | ||
return internals.serverError(message, data, statusCode, exports.internal); | ||
}; | ||
if (data instanceof Error === false) { | ||
internals.serverError = function (message, data, statusCode, ctor) { | ||
var error; | ||
if (data instanceof Error) { | ||
error = exports.wrap(data, statusCode, message); | ||
} else { | ||
error = internals.create(statusCode || 500, message, ctor); | ||
error.data = data; | ||
@@ -297,3 +308,3 @@ } | ||
return exports.internal(message, data, 501); | ||
return internals.serverError(message, data, 501, exports.notImplemented); | ||
}; | ||
@@ -304,3 +315,3 @@ | ||
return exports.internal(message, data, 502); | ||
return internals.serverError(message, data, 502, exports.badGateway); | ||
}; | ||
@@ -311,3 +322,3 @@ | ||
return exports.internal(message, data, 503); | ||
return internals.serverError(message, data, 503, exports.serverTimeout); | ||
}; | ||
@@ -318,3 +329,3 @@ | ||
return exports.internal(message, data, 504); | ||
return internals.serverError(message, data, 504, exports.gatewayTimeout); | ||
}; | ||
@@ -325,5 +336,5 @@ | ||
var err = exports.internal(message, data, 500); | ||
var err = internals.serverError(message, data, 500, exports.badImplementation); | ||
err.isDeveloperError = true; | ||
return err; | ||
}; |
{ | ||
"name": "boom", | ||
"description": "HTTP-friendly error objects", | ||
"version": "2.8.0", | ||
"version": "2.9.0", | ||
"repository": "git://github.com/hapijs/boom", | ||
@@ -12,3 +12,3 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.8.0" | ||
"node": ">=0.10.40" | ||
}, | ||
@@ -23,6 +23,6 @@ "dependencies": { | ||
"scripts": { | ||
"test": "lab -a code -t 100", | ||
"test-cov-html": "lab -a code -r html -o coverage.html" | ||
"test": "lab -a code -t 100 -L", | ||
"test-cov-html": "lab -a code -r html -o coverage.html -L" | ||
}, | ||
"license": "BSD-3-Clause" | ||
} |
@@ -82,3 +82,3 @@ // Load modules | ||
{ input: 400, result: 400 }, | ||
{ input: 400.123, result: 400 }] | ||
{ input: 400.123, result: 400 }]; | ||
for (var i = 0, il = codes.length; i < il; ++i) { | ||
@@ -85,0 +85,0 @@ var code = codes[i]; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69496
612