🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

error-status-helper

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

error-status-helper

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

latest
Source
npmnpm
Version
2.1.2
Version published
Maintainers
1
Created
Source

error-status-helper

Extends express response middleware with status codes helper methods.

Installation

$ npm install error-status-helper

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"});

FAQs

Package last updated on 16 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts