esh

error-status-helper

Extends node.js response prototype with status codes helper methods.

Showing:

Popularity

Downloads/wk

6

GitHub Stars

0

Maintenance

Last Commit

2yrs ago

Contributors

4

Package

Dependencies

0

Size (min+gzip)

0.5KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

error-status-helper

Extends express response middleware with status codes helper methods.

Installation

NPM

Example

javascript

  • simple example
var express = require('express');
var errorStatus = require('error-status-helper');
errorStatus(express);

var app = express();

// catch 404 and forward to error handler
app.use(statusHelper.notFoundMiddleware);


// error handler
app.use(statusHelper.errorMiddleware);

Using sendData packaging return values only available in express

register: (req, res, next) => {
    const body = req.body;
    return new promise((resolve, reject) => {
        if (body.user && body.password && body.phone) {
            return resolve(body);
        }
        else {
            return reject(errorStatus.Parameter_Error);
        }
    }).then(data => {
        return userInfoModule.register(body);
    }).then(data => {
        res.sendData(data);
    }).catch(err => {
        next(err, req, res);
    });
}

Using extendStatus extended state information

errorStatus.extendStatus('User_Has_Registered', {code: 202, statusCode: 202001, message: "The user has been registered"});

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