errorable-express
v0.0.4
Published
express middleware for errorable
Downloads
9
Readme
errorable-express
express middleware for errorable
Installation
$ npm install --save errorable-express
API
- res.errors
Keeps all errors defined, like res.errors.Success. - 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