Error handling for Node.js and Express
To install:
npm install @holmwell/errors
To use:
var errors = require("@holmwell/errors");
Logs an Error object, or just a string, to the console. Future versions may log to some framework.
Used for refactoring all your error conditionals. That is, it is for turning code like this:
db.circles.getAll(function (err, circles) {
if (err) {
handleError(err, res);
}
// <deal with circles>
});
Into this:
db.circles.getAll(guard(res, function (circles) {
// <deal with circles>
}));
Primarily used internally, but you can also use it to send and an error code back to the Express client.
Handle uncaught errors in your Express middleware stack. Typically this should be put near the end / bottom of your middleware.
var app = require('express')();
// Define routes, app.use(...), etc
app.use(errors.middleware);
This module is available under a BSD 2-clause license.
Phil Manijak / Holmwell Software