Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-error-handler - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

error-handler.js

@@ -19,2 +19,3 @@ /**

var mixIn = require('mout/object/mixIn'),
createObject = require('mout/lang/createObject'),
path = require('path'),

@@ -110,3 +111,3 @@ fs = require('fs'),

body = (o.serializer) ?
o.serializer(body) :
o.serializer(createObject(err, body)) :
body;

@@ -117,3 +118,3 @@

},
defaults = {

@@ -120,0 +121,0 @@ handlers: {},

29

package.json
{
"name": "express-error-handler",
"version": "1.0.1",
"version": "1.1.0",
"description": "A graceful error handler for Express applications.",
"main": "error-handler.js",
"scripts": {
"test": "node ./test/runtests.js"
"lint": "grunt hint",
"pretest": "npm run -s lint",
"test": "node ./test/runtests.js",
"watch": "watch 'clear && npm run -s test' .",
"start-example": "node examples/app.js | bunyan",
"latest": "updtr"
},

@@ -27,17 +32,17 @@ "repository": {

"dependencies": {
"connect-domain": "~0.5.0",
"json-stringify-safe": "^5.0.0",
"mout": "~0.7.1"
"mout": "0.12.0"
},
"devDependencies": {
"bunyan-request-logger": "~0.1.1",
"connect-cache-control": "~0.1.0",
"bunyan-request-logger": "1.0.2",
"connect-cache-control": "1.0.0",
"express": "^4.9.8",
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.4",
"restify": "~2.6.0",
"supertest": "~0.8.0",
"tape": "~1.1.1",
"through": "~2.3.4"
"grunt-contrib-jshint": "1.0.0",
"restify": "4.0.4",
"supertest": "1.2.0",
"tape": "4.5.1",
"through": "~2.3.4",
"updtr": "0.1.7",
"watch": "0.17.1"
}
}

@@ -110,2 +110,21 @@ express-error-handler

Or for a custom JSON object:
```js
var errorHandler = require('express-error-handler'),
handler = errorHandler({
serializer: function(err) {
var body = {
status: err.status,
message: err.message
};
if (createHandler.isClientError(err.status)) {
['code', 'name', 'type', 'details'].forEach(function(prop) {
if (err[prop]) body[prop] = err[prop];
});
}
return body;
}
});
```
[More examples](https://github.com/dilvie/express-error-handler/tree/master/examples) are available in the examples folder.

@@ -164,5 +183,5 @@

Written by [Eric Elliott](http://ericelliottjs.com/) for the book, ["Programming JavaScript Applications"](http://www.amazon.com/gp/product/1491950293?ie=UTF8&camp=213733&creative=393185&creativeASIN=1491950293&linkCode=shr&tag=eejs-20&linkId=TSFLZ3FJX2X4WZ5H) (O'Reilly)
Written by [Eric Elliott](http://ericelliottjs.com/) for the book, ["Programming JavaScript Applications"](http://pjabook.com) (O'Reilly)
* [Nam Nguyen](https://github.com/gdbtek) for bringing the Express DOS exploit to my attention.
* [Samuel Reed](https://github.com/strml) for helpful suggestions.

@@ -113,3 +113,3 @@ 'use strict';

render: function render() {
t.pass('Render should be called for ' +
t.pass('Render should be called for ' +
'custom views.');

@@ -125,3 +125,3 @@ t.end();

test('Error with status default behavior',
test('Error with status default behavior',
function (t) {

@@ -151,3 +151,3 @@

test('Default error status for non-user error',
test('Default error status for non-user error',
function (t) {

@@ -176,3 +176,3 @@

test('Custom timeout',
test('Custom timeout',
function (t) {

@@ -310,3 +310,3 @@

test('JSON error format',
test('JSON error format',
function (t) {

@@ -322,6 +322,6 @@

t.equal(obj.status, 500,
'res.send() should be called ' +
'res.send() should be called ' +
'with error status on response body.');
t.equal(obj.message, 'Internal Server Error',
'res.send() should be called ' +
'res.send() should be called ' +
'with error message on response body.');

@@ -340,3 +340,3 @@ t.end();

test('JSON with custom error message',
test('JSON with custom error message',
function (t) {

@@ -352,3 +352,3 @@

t.equal(obj.message, 'half baked',
'res.send() should be called ' +
'res.send() should be called ' +
'with custom error message.');

@@ -369,3 +369,3 @@ t.end();

test('JSON with serializer',
test('JSON with serializer',
function (t) {

@@ -377,6 +377,6 @@

shutdown: shutdown,
serializer: function (body) {
serializer: function (err) {
return {
status: body.status,
message: body.message,
status: err.status,
message: err.message,
links: [

@@ -389,3 +389,3 @@ {self: '/foo'}

res = testRes({
send: function send(obj) {
send: function send(obj) {
t.equal(obj.links[0].self, '/foo',

@@ -405,1 +405,32 @@ 'Should be able to define a custom ' +

});
test('JSON with serializer with access to error object',
function (t) {
var shutdown = function shutdown() {},
e = (function () {
var err = new Error();
err.status = 400;
['code', 'name', 'type', 'details'].forEach(function(prop) { err[prop] = 'foo'; });
return err;
}()),
handler = createHandler({
shutdown: shutdown,
serializer: function(err) { return err; }
}),
res = testRes({
send: function send(obj) {
var propertiesPass = ['code', 'name', 'type', 'details'].every(function(prop) {
return obj[prop] === 'foo';
});
t.ok(propertiesPass,
'Should be able to write custom serializer with access to properties of client errors.');
t.end();
},
format: function format (types) {
return types['json']();
}
});
handler(e, testReq(), res, testNext);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc