node-socketerrors
Exposes a function mapping socket errors to SocketError objects.
The defined SocketError objects are created via createerror.
Installation
Make sure you have node.js and npm installed, then run:
npm install socketerrors
Usage
The primary use case is wrapping errors originating from socket operations:
var http = require('http');
var socketErrors = require('socketerrors');
http.get('nonexistent').on('error', function (err) {
var socketError = socketErrors(err);
console.warn(socketError.toString()); // ECONNREFUSED: connect ECONNREFUSED
});
Other errors will be marked as not being socket errors:
var socketErrors = require('socketerrors');
var err = new Error();
var socketError = socketErrors(err);
if (socketError.NotSocketError) {
// what am I?
}
Mappings
The following is a list of socket errors mapped by this module:
- EADDRINFO
- ECONNABORTED
- ECONNREFUSED
- ECONNRESET
- ENETDOWN
- ENETRESET
- ENETUNREACH
- ETIMEDOUT
License
3-clause BSD license -- see the LICENSE
file for details.