socketerrors
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -5,9 +5,39 @@ var createError = require('createerror'); | ||
var SocketError = createError({ name: 'SocketError' }); | ||
function allKeys(o) { | ||
var keys = []; | ||
for (var key in o) keys.push(key); | ||
return keys; | ||
} | ||
function createSocketError(errorCode) { | ||
var statusCode = socketCodesMap[errorCode] || 'Unknown'; | ||
return socketErrors[errorCode] = createError({ | ||
var options = { | ||
name: errorCode, | ||
code: errorCode | ||
}, httpErrors[statusCode]); | ||
code: errorCode, | ||
statusCode: statusCode, | ||
status: statusCode | ||
}; | ||
// get constructed httpError to use to grab what we need to 'quack' like it | ||
var httpError = httpErrors(statusCode); | ||
var httpErrorKeys = allKeys(httpError); | ||
// copy keys from the httpError to the socketError | ||
httpErrorKeys.forEach(function (key) { | ||
if (!options[key] && key !== 'message') { | ||
options[key] = httpError[key]; | ||
} | ||
}); | ||
// create the socket error object | ||
var socketError = createError(options, SocketError); | ||
socketErrors[errorCode] = socketError; | ||
return socketError; | ||
} | ||
@@ -27,2 +57,5 @@ | ||
// export the base class | ||
module.exports.SocketError = SocketError; | ||
// create an Unknown error sentinel | ||
@@ -29,0 +62,0 @@ socketErrors.NotSocketError = createSocketError('NotSocketError'); |
{ | ||
"name": "socketerrors", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Maps socket errors to SocketError objects subclassing httperrors.", | ||
@@ -16,3 +16,3 @@ "main": "lib/socketErrors.js", | ||
"createerror": "1.0.0", | ||
"httperrors": "0.7.1" | ||
"httperrors": "1.2.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "devDependencies": { |
@@ -7,4 +7,3 @@ node-socketerrors | ||
Exposes a function mapping socket errors to SocketError objects subclassing | ||
<a href="https://github.com/One-com/node-httperrors">httperrors</a>. | ||
Exposes a function mapping socket errors to SocketError objects. | ||
@@ -11,0 +10,0 @@ The defined SocketError objects are created via |
@@ -26,2 +26,4 @@ var expect = require('unexpected'); | ||
expect(socketError, 'to be a', socketErrors.SocketError); | ||
done(); | ||
@@ -28,0 +30,0 @@ }); |
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
8712
128
8
63
+ Addedcreateerror@1.0.1(transitive)
+ Addedhttperrors@1.2.0(transitive)
- Removedcreateerror@0.5.1(transitive)
- Removedhttperrors@0.7.1(transitive)
Updatedhttperrors@1.2.0