errorable-express 0.0.2 released

21 views
Skip to first unread message

李白|字一日

unread,
Feb 21, 2016, 9:24:51 AM2/21/16
to sai...@googlegroups.com, nod...@googlegroups.com
hi, all

Errorable is ready for integration with expressjs.

Errorable is a try to solve problems in defining, migrating, exchanging of errors between projects or companies .

1. Errorable can be easily defined according to very simple rules.
2. Errorable can be easily expand to more than one languaes
3. Errorable can be easily customized to your own needs and can easily get what is predefined.

the errorable project is here:
https://github.com/calidion/errorable

currently available errors are:
1. http errors 
https://github.com/Errorable/http
2.  common errors
https://github.com/Errorable/common


the expressjs middleware is here:
https://github.com/Errorable/express-middleware


the following code shows how it works.
var errorableExpress = require('errorable-express');   //the errorable middleware for express
var common = require('errorable-common');    //predefined or customized errors
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

express.use(errorableExpress(errors));             //added errorable to expressjs as a middleware

express.get('/', function indexxx(req, res) {
  res.restify(res.errors.Success);                //We get extended res object with new apis and the errors attribute.
});
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();
});

Thanks & enjoy.

李白字一日

unread,
Feb 23, 2016, 11:01:11 PM2/23/16
to sails.js, nod...@googlegroups.com

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',
    ...
    ]



在 2016年2月21日星期日 UTC+8下午6:32:17,李白字一日写道:
Reply all
Reply to author
Forward
0 new messages