Error handling utilities for node
JavaScript OCaml
Latest commit c84eae7 Jun 29, 2015 @Raynos Merge pull request #11 from shesek/iserror
use util.isError() to properly detect assert errors
Permalink
Failed to load latest commit information.
test add failing test case for wrapping assert errors Jun 30, 2015
.gitignore typed.js should pass other options through Aug 23, 2013
.istanbul.yml less dependencies May 6, 2015
MIGRATION.md migration docs Jun 12, 2015
README.md implement wrapped error Mar 9, 2015
docs.mli
io.js Use the term "cause" instead of "originalError" Mar 18, 2015
option.js set type to be enumerable on errors Aug 23, 2013
package.json 7.0.1 May 29, 2015
typed.js typed: set fullType to resolved type instead of raw type May 29, 2015
validation.js set type to be enumerable on errors Aug 23, 2013
wrapped.js use util.isError() to properly detect assert errors (and possibly oth… Jun 30, 2015

README.md

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