dat-middleware
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -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, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48865
7
1265
1
+ Addedmap-utils@0.3.0(transitive)
- Removedlodash@~2.4.1
- Removedlodash@2.4.2(transitive)
- Removedmap-utils@0.2.0(transitive)
Updatedmap-utils@^0.3.0