nce

node-common-errors

Predefined extended error classes, which can be used in any node.js-based framework for easily handling different error cases

Showing:

Popularity

Downloads/wk

2

GitHub Stars

1

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

2

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Node Errors

Extended Node.JS Error classes, allowing you to easily handle common errors in a web application. Predefined error messages and codes will save you some time and boilerplate code.

Furthermore, it contains a common error handler middleware, which complements forming responses based on the errors that had been passed

Error types

NameMessageCodePayloadSignature
Commonnull400nullmessage, code
AuthNot authorized401nullmessage
ForbiddenForbidden403nullmessage
NotFoundNot Found404nullmessage
BadRequestBad Request400nullpayload
UninitializedUninitialized500null
InternalInternal Server Error500nullmessage

Usage

One of the many usage cases

var Errors = require('node-common-errors');
var express = require('express');
var app = express();


var router = express.Router();

// custom router, for now it's in the same file, but it's more
// and more common to have components-based web servers, so let's keep it
// that way
router
  .post('/register', function (req, res, next) {
    var body = req.body;
    var username = body.username;
    var password = body.password;

    if (!username) {
      return next(new Errors.BadRequest('missing.username'));
    }

    if (!password) {
      return next(new Errors.BadRequest('missing.password'));
    }

    if (password.length < 10) {
      return next(new Errors.BadRequest('password.small'));
    }

    // etc, we can do various check, you get the idea

    res.send('OK');

  });


app.use(router);
app.use(Errors.commonErrorHandler);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial