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

dat-middleware

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dat-middleware - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

35

lib/errorHandler.js

@@ -1,5 +0,11 @@

var _ = require('lodash');
var utils = require('map-utils');
var pick = require('map-utils').pick;
var exists = require('map-utils').exists;
var NODE_ENV = process.env.NODE_ENV;
module.exports = function (opts) {
opts = opts || {};
opts.showStack = exists(opts.showStack) ? opts.showStack :
NODE_ENV === 'development';
opts.log = exists(opts.log) ? opts.log :
NODE_ENV !== 'testing';
var keys = ['message'];

@@ -10,17 +16,24 @@ if (opts.showStack) {

return function (err, req, res, next) {
if (opts.log) logErrors(err);
var errs;
if (Array.isArray(err)) {
errs = err.map(utils.pick(keys));
var statusCode = _.first(errs).output.statusCode;
errs = err.map(pick(keys));
var statusCode = errs[0].output.statusCode;
res.json(statusCode, { errors: errs });
}
else if (err.isBoom) {
res.json(err.output.statusCode, pick(keys)(err));
}
else {
if (err.isBoom) {
res.json(err.output.statusCode, _.pick(err, keys));
}
else {
res.json(500, _.pick(err, keys));
}
res.json(500, pick(keys)(err));
}
};
};
};
function logErrors (errs) {
errs = Array.isArray(errs) ? errs : [errs];
errs.forEach(function (err) {
console.error(err);
console.error(err.stack);
});
}

@@ -1,2 +0,1 @@

var _ = require('lodash');
var error = require('./error');

@@ -3,0 +2,0 @@ var utils = require('map-utils');

{
"name": "dat-middleware",
"version": "1.1.0",
"version": "1.1.1",
"description": "common request, response, body, query, and param validation, transformation, and flow control middleware",

@@ -34,3 +34,2 @@ "main": "index.js",

"joi": "~2.7.0",
"lodash": "~2.4.1",
"boom": "~2.2.0",

@@ -41,3 +40,3 @@ "callback-count": "0.0.3",

"middleware-flow": "^0.2.0",
"map-utils": "^0.2.0"
"map-utils": "^0.3.0"
},

@@ -44,0 +43,0 @@ "devDependencies": {

@@ -9,3 +9,3 @@ var express = require('express');

app.use(app.router);
app.use(mw.errorHandler({ showStack: true }));
app.use(mw.errorHandler({ showStack: true, log: false }));
app.all('/body',

@@ -12,0 +12,0 @@ // inspect,

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