Opal-Estate-Pro/node_modules/error
2019-09-13 11:27:52 +07:00
..
node_modules/xtend style Dashboard 2019-09-13 11:27:52 +07:00
test style Dashboard 2019-09-13 11:27:52 +07:00
.istanbul.yml style Dashboard 2019-09-13 11:27:52 +07:00
.npmignore style Dashboard 2019-09-13 11:27:52 +07:00
docs.mli style Dashboard 2019-09-13 11:27:52 +07:00
io.js style Dashboard 2019-09-13 11:27:52 +07:00
MIGRATION.md style Dashboard 2019-09-13 11:27:52 +07:00
option.js style Dashboard 2019-09-13 11:27:52 +07:00
package.json style Dashboard 2019-09-13 11:27:52 +07:00
README.md style Dashboard 2019-09-13 11:27:52 +07:00
typed.js style Dashboard 2019-09-13 11:27:52 +07:00
validation.js style Dashboard 2019-09-13 11:27:52 +07:00
wrapped.js style Dashboard 2019-09-13 11:27:52 +07:00

error

Custom errors

Typed Error

var TypedError = require("error/typed")

var ServerError = TypedError({
    type: 'server.5xx',
    message: '{title} server error, status={statusCode}',
    title: null,
    statusCode: null
});
var ClientError = TypedError({
    type: 'client.4xx',
    message: '{title} client error, status={statusCode}',
    title: null,
    statusCode: null
});

var error = ServerError({
    title:'some title',
    statusCode: 500
});
var error2 = ClientError({
    title: 'some title',
    statusCode: 404
});

Wrapped Errors

var net = require('net');
var WrappedError = require('error/wrapped');

var ServerListenError = WrappedError({
    message: 'server: {origMessage}',
    type: 'server.listen-failed',
    requestedPort: null,
    host: null
});

var server = net.createServer();

server.on('error', function onError(err) {
    if (err.code === 'EADDRINUSE') {
        throw ServerListenError(err, {
            requestedPort: 3000,
            host: null
        });
    } else {
        throw err;
    }
});

server.listen(3000);

Installation

npm install error

Contributors

  • Raynos

MIT Licenced