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 0.4.0 to 0.5.0

27

error-handler.js

@@ -103,3 +103,4 @@ /**

server: undefined,
shutdown: undefined
shutdown: undefined,
serializer: undefined
},

@@ -142,2 +143,6 @@ createHandler;

*
* @param {function} serializer a function to
* customize the JSON error object.
* Usage: serializer(err) return errObj
*
* @return {function} errorHandler Express error

@@ -195,3 +200,21 @@ * handling middleware.

}
return res.send(status);
return res.format({
text: function () {
res.send(status);
},
html: function () {
res.send(status);
},
json: function () {
var body = mixIn({}, err, {
status: status,
message: statusCodes[status]
});
body = (o.serializer) ?
o.serializer(body) :
body;
res.send(status, body);
}
});
},

@@ -198,0 +221,0 @@

2

package.json
{
"name": "express-error-handler",
"version": "0.4.0",
"version": "0.5.0",
"description": "A graceful error handler for Express applications.",

@@ -5,0 +5,0 @@ "main": "error-handler.js",

@@ -60,2 +60,3 @@ express-error-handler

* @param {function} [options.shutdown] An alternative shutdown function if the graceful shutdown fails.
* @param {function} serializer a function to customize the JSON error object. Usage: serializer(err) return errObj
* @return {function} errorHandler Express error handling middleware.

@@ -94,3 +95,3 @@

* // 405 for unsupported methods.
* app.all( '/foo', createHandler.err(405) );
* app.all( '/foo', createHandler.httpError(405) );
```

@@ -97,0 +98,0 @@

@@ -7,2 +7,6 @@ 'use strict';

format = function format (types) {
return types['text']();
},
testError = new Error('Test error'),

@@ -12,3 +16,4 @@ testReq = function () { return {}; },

return {
send: function send() {}
send: function send() {},
format: format
};

@@ -106,3 +111,3 @@ },

handler(e, testReq(), {
send: function send(status) {
send: function send(status) {
t.equal(status, 404,

@@ -112,4 +117,5 @@ 'res.send() should be called ' +

t.end();
}
}, testNext);
},
format: format
}, testNext);
});

@@ -134,4 +140,5 @@

t.end();
}
}, testNext);
},
format: format
}, testNext);
});

@@ -269,1 +276,65 @@

});
test('JSON error format',
function (t) {
var shutdown = function shutdown() {},
e = new Error(),
handler = createHandler({
shutdown: shutdown
});
e.status = 500;
handler(e, testReq(), {
send: function send(status, obj) {
t.equal(obj.status, 500,
'res.send() should be called ' +
'with status code as first param.');
t.equal(obj.status, 500,
'res.send() should be called ' +
'with error status on response body.');
t.equal(obj.message, 'Internal Server Error',
'res.send() should be called ' +
'error message on response body.');
t.end();
},
format: function format (types) {
return types['json']();
}
}, testNext);
});
test('JSON with serializer',
function (t) {
var shutdown = function shutdown() {},
e = new Error(),
handler = createHandler({
shutdown: shutdown,
serializer: function (body) {
return {
status: body.status,
message: body.message,
links: [
{self: body.route}
]
};
}
});
e.status = 500;
e.route = '/foo';
handler(e, testReq(), {
send: function send(status, obj) {
t.equal(obj.links[0].self, '/foo',
'Should be able to define a custom' +
'serializer for error responses.');
t.end();
},
format: function format (types) {
return types['json']();
}
}, 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