1.0.1 • Published 9 years ago

express-response-error v1.0.1

Weekly downloads
31
License
MIT
Repository
github
Last release
9 years ago

express-response-error

Send errors easily right from response object (eg. res.notFound('not found') -> 404 {"error":"not found"}).

Build Status

Example

 var express = require('express');
 var expressResponseError = require('express-response-error');

 app = new express();
 
 var options = {};
 app.use(expressResponseError(options));

 app.get('/test/forbidden',(req,res,next)->
  res.forbidden('this resource is forbidden');
 )
 
 app.get('/test/custom',(req,res,next)->
  res.error('something bad has happened',444);
 )
 
 // handle formatting to suite your needs
 app.use((err,req,res,next)->
   res.status(err.code).send({error: err.message})
 )

 app.listen(process.env.PORT)

Options

  • curlify - return curl for request
  • logging - log every error payload with console.error
  • stackLogging - include error stack in payload
  • translation - translate error message (default null)
    • specify translate function accepting one argument
    • string i18n to use translation for i18n)

Translations with i18n

 var express = require('express');
 var expressResponseError = require('express-response-error');
 var i18n = require('i18n');

 i18n.configure({
    locales:['en','de']
 })

 app = new express();
 
 var options = {
    translate:'i18n'
 };
 app.use(expressResponseError(options));
 app.use(i18n.init)
 
 app.get('*',(req,res,next)->
  res.error('SOME_ERROR'); // this message gets translated with dictionary 
 )

 app.listen(process.env.PORT)

Debug

If you app is not running in production (process.env.NODE_ENV == 'production') or if you specify ?debug=1 in request stack is returned in response.

1.0.1

9 years ago

1.0.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago