Skip to content
Errorable middleware for express
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.editorconfig
.eslintrc
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
gulpfile.js
package.json

README.md

errorable-express NPM version Build Status Dependency Status Coverage percentage

express middleware for errorable

Installation

$ npm install --save errorable-express

API

  1. res.errors
    Keeps all errors defined, like res.errors.Success.
  2. res.errorize/res.restify
    Generate the json object for the error and insert data if possible

Usage

Expressjs Middleware

var errorableExpress = require('errorable-express');
var common = require('errorable-common');
var errorable = require('errorable');
var Generator = errorable.Generator;
var errors = new Generator(common, 'zh-CN').errors;

express.use(errorableExpress(errors));

express.get('/', function indexxx(req, res) {
  res.restify(res.errors.Success);
});
express.get('/message', function messagexx(req, res) {
  res.restify(res.errors.Success, message);
});

express.get('/unknown', function unknownxx(req, res) {
  res.restify();
});

express.get('/errorize', function errorizexx(req, res) {
  //restify === errorize
  res.errorize();
});

Integration with Sailsjs

in config/http.js

    //Create a new middleware function
    errorable: function(req, res, next) {
      var errorableExpress = require('errorable-express');   //the errorable middleware for express
      var common = require('errorable-common');   //the errorable middleware for express
      var errorable = require('errorable');	     //the errorable library
      var Generator = errorable.Generator;	     //Get the generator
      var errors = new Generator(common, 'zh-CN').errors;    //Generate the errors
      var callback = errorableExpress(errors);
      callback(req, res, next);
    },
    
    //Added it to the order array
    order: [
    ...
    'errorable',
    ...
    ]

License

MIT © calidion

You can’t perform that action at this time.