Comparing version 1.3.1 to 1.3.2
@@ -9,4 +9,2 @@ /* vim: set softtabstop=4 ts=4 sw=4 expandtab tw=120 syntax=javascript: */ | ||
var _ = require('lodash'); | ||
var DEFAULT_LOGGER = console; | ||
@@ -17,3 +15,3 @@ | ||
opts = opts || {}; | ||
if (_.isString(opts)) { opts = {message: opts}; } | ||
if (typeof opts === 'string') { opts = {message: opts}; } | ||
this.message = opts.message || 'An error occurred.'; | ||
@@ -24,4 +22,4 @@ this.data = opts.data || ''; | ||
this.isAppError = true; | ||
this.logError = _.isUndefined(opts.logError) && true || opts.logError; | ||
this.captureStack = _.isUndefined(opts.captureStack) && true || opts.captureStack; | ||
this.logError = typeof opts.logError !== 'boolean' && true || opts.logError; | ||
this.captureStack = typeof opts.captureStack !== 'boolean' && true || opts.captureStack; | ||
if (this.captureStack) { | ||
@@ -46,7 +44,6 @@ Error.captureStackTrace(this, (context || AppError)); | ||
logger = logger || this.DEFAULT_LOGGER || DEFAULT_LOGGER; | ||
var logged = _.find(this._logged, {logger: logger}); | ||
if (!this.logError || this.logError && logged) { | ||
if (typeof logger.error !== 'function' || !this.logError || this.logError || this._logged.length) { | ||
return this; | ||
} | ||
this._logged.push({logger: logger}); | ||
this._logged.push({logger}); | ||
logger.error(this.toJSON()); | ||
@@ -61,9 +58,9 @@ var stack = this.stack; | ||
if (!(this instanceof Error)) { return new CustomError(msgOrOpts, code, data); } | ||
var opts = _.extend({}, defaults); | ||
if (_.isObject(msgOrOpts)) { | ||
var opts = Object.assign({}, defaults); | ||
if (msgOrOpts && typeof msgOrOpts === 'object') { | ||
opts.message = msgOrOpts.message || msgOrOpts.msg || opts.message || opts.msg; | ||
opts.code = msgOrOpts.code || msgOrOpts.status || msgOrOpts.statusCode || opts.code || opts.status || opts.statusCode; | ||
opts.data = msgOrOpts.data || opts.data; | ||
if (!_.isUndefined(msgOrOpts.captureStack)) { opts.captureStack = msgOrOpts.captureStack; } | ||
if (!_.isUndefined(msgOrOpts.logError)) { opts.logError = msgOrOpts.logError; } | ||
if (typeof msgOrOpts.captureStack === 'boolean') { opts.captureStack = msgOrOpts.captureStack; } | ||
if (typeof msgOrOpts.logError === 'boolean') { opts.logError = msgOrOpts.logError; } | ||
} else { | ||
@@ -70,0 +67,0 @@ opts.message = msgOrOpts || opts.message || opts.msg; |
@@ -5,3 +5,3 @@ { | ||
"repository": "https://github.com/gradecam/nodejs-apperror", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "A customizable application error generator.", | ||
@@ -11,6 +11,3 @@ "main": "apperror.js", | ||
"author": "Jarom Loveridge <jaroml@gradecam.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"lodash": "^4.17.11" | ||
} | ||
"license": "MIT" | ||
} |
0
8004
64
- Removedlodash@^4.17.11
- Removedlodash@4.17.21(transitive)