Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

socketerrors

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socketerrors - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

16

lib/socketCodesMap.js
module.exports = {
EADDRINFO: 502,
ECONNABORTED: 502,
ECONNREFUSED: 504,
ECONNRESET: 502,
ENETDOWN: 504,
ENETRESET: 502,
ENETUNREACH: 504,
ETIMEDOUT: 504
EADDRINFO: 502,
ECONNABORTED: 502,
ECONNREFUSED: 504,
ECONNRESET: 502,
ENETDOWN: 504,
ENETRESET: 502,
ENETUNREACH: 504,
ETIMEDOUT: 504
};

@@ -6,66 +6,76 @@ var createError = require('createerror');

function allKeys(o) {
var keys = [];
var keys = [];
for (var key in o) keys.push(key);
for (var key in o) keys.push(key);
return keys;
return keys;
}
function createSocketError(errorCode) {
var statusCode = socketCodesMap[errorCode] || 'Unknown';
var statusCode = socketCodesMap[errorCode] || 'Unknown';
var options = {
name: errorCode,
code: errorCode,
statusCode: statusCode,
status: statusCode
};
var options = {
name: errorCode,
code: errorCode,
statusCode: statusCode,
status: statusCode
};
// get constructed httpError to use to grab what we need to 'quack' like it
var httpError = HttpError(statusCode);
var httpErrorKeys = allKeys(httpError);
// get constructed httpError to use to grab what we need to 'quack' like it
var httpError = HttpError(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];
}
});
options.http = false;
options.HttpError = false;
SocketError[errorCode] = createError(options, SocketError);
// copy keys from the httpError to the socketError
httpErrorKeys.forEach(function(key) {
if (!options[key] && key !== 'message') {
options[key] = httpError[key];
}
});
options.http = false;
options.HttpError = false;
SocketError[errorCode] = createError(options, SocketError);
}
var SocketError = module.exports = createError({
name: 'SocketError',
preprocess: function (err) {
if (!(err instanceof SocketError) && err !== 'NotSocketError') {
if (!SocketError.supports(err)) {
if (err) {
var errOptions = {};
if (err.code) {
errOptions.code = err.code;
}
}
var SocketError = (module.exports = createError({
name: 'SocketError',
preprocess: function(err) {
if (!(err instanceof SocketError) && err !== 'NotSocketError') {
if (!SocketError.supports(err)) {
if (err) {
var errOptions = {};
if (err.code) {
errOptions.code = err.code;
}
}
return new SocketError.NotSocketError(errOptions);
}
return new SocketError.NotSocketError(errOptions);
}
if (typeof err === 'string') {
return new SocketError[err]();
} else if (err && err.code && socketCodesMap.hasOwnProperty(err.code)) {
return new SocketError[err.code](err);
}
}
if (typeof err === 'string') {
return new SocketError[err]();
} else if (
err &&
err.code &&
Object.prototype.hasOwnProperty.call(socketCodesMap, err.code)
) {
return new SocketError[err.code](err);
}
}
});
}
}));
SocketError.supports = function (errorOrErrorCode) {
if (typeof errorOrErrorCode === 'string') {
return socketCodesMap.hasOwnProperty(errorOrErrorCode);
} else if (errorOrErrorCode && errorOrErrorCode.code) {
return socketCodesMap.hasOwnProperty(errorOrErrorCode.code);
} else {
return false;
}
SocketError.supports = function(errorOrErrorCode) {
if (typeof errorOrErrorCode === 'string') {
return Object.prototype.hasOwnProperty.call(
socketCodesMap,
errorOrErrorCode
);
} else if (errorOrErrorCode && errorOrErrorCode.code) {
return Object.prototype.hasOwnProperty.call(
socketCodesMap,
errorOrErrorCode.code
);
} else {
return false;
}
};

@@ -72,0 +82,0 @@

{
"name": "socketerrors",
"version": "0.3.0",
"version": "1.0.0",
"description": "Maps socket errors to SocketError objects subclassing httperrors.",
"main": "lib/SocketError.js",
"scripts": {
"lint": "eslint . && prettier --check '**/*.js'",
"test": "mocha"
},
"author": {
"name": "Alex J Burke",
"email": "alex@alexjeffburke.com"
"files": [
"lib"
],
"author": "Alex J Burke <alex@alexjeffburke.com>",
"repository": {
"type": "git",
"url": "https://github.com/alexjeffburke/node-socketerrors.git"
},

@@ -19,5 +24,14 @@ "license": "BSD",

"devDependencies": {
"mocha": "2.4.5",
"unexpected": "10.8.2"
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-mocha": "^6.2.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "6.2.2",
"prettier": "~1.19.1",
"unexpected": "10.40.2"
}
}

@@ -1,6 +0,5 @@

node-socketerrors
=================
# node-socketerrors
[![NPM version](https://badge.fury.io/js/socketerrors.svg)](http://badge.fury.io/js/socketerrors)
[![Build Status](https://travis-ci.org/alexjeffburke/node-socketerrors.svg?branch=master)](https://travis-ci.org/alexjeffburke/unode-socketerrors)
[![NPM version](https://img.shields.io/npm/v/socketerrors.svg)](http://badge.fury.io/js/socketerrors)
[![Build Status](https://img.shields.io/travis/alexjeffburke/node-socketerrors/master.svg)](https://travis-ci.org/alexjeffburke/unode-socketerrors)

@@ -12,4 +11,3 @@ Exposes a function mapping socket errors to SocketError objects.

Installation
------------
## Installation

@@ -20,4 +18,3 @@ Make sure you have node.js and npm installed, then run:

Usage
-----
## Usage

@@ -35,3 +32,2 @@ The primary use case is wrapping errors originating from socket operations:

Other errors will be marked as not being socket errors:

@@ -48,19 +44,17 @@

Mappings
--------
## Mappings
The following is a list of socket errors mapped by this module:
* EADDRINFO
* ECONNABORTED
* ECONNREFUSED
* ECONNRESET
* ENETDOWN
* ENETRESET
* ENETUNREACH
* ETIMEDOUT
- EADDRINFO
- ECONNABORTED
- ECONNREFUSED
- ECONNRESET
- ENETDOWN
- ENETRESET
- ENETUNREACH
- ETIMEDOUT
License
-------
## License
3-clause BSD license -- see the `LICENSE` file for details.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc