@c8/errors
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -9,4 +9,1 @@ module.exports = { | ||
} | ||
// NotUpdatedError | ||
// NotRemovedError |
@@ -7,11 +7,8 @@ 'use strict' | ||
SizeError: createError('SizeError'), | ||
TypeError: createError('TypeError'), | ||
ReadError: createError('ReadError'), | ||
PermissionDeniedError: createError('PermissionDeniedError'), | ||
NotFoundError: createError('NotFoundError'), | ||
NotUpdatedError: createError('NotUpdatedError'), | ||
NotRemovedError: createError('NotRemovedError'), | ||
InvalidInputError: createError('InvalidInputError'), | ||
TimeoutError: createError('TimeoutError'), | ||
AlreadyExistsError: createError('AlreadyExistsError') | ||
AlreadyExistsError: createError('AlreadyExistsError'), | ||
NotImplementedError: createError('AlreadyExistsError') | ||
} |
@@ -6,3 +6,3 @@ 'use strict' | ||
const Errors = require('./errors') | ||
const mapping = require('./boom-mapping') | ||
const defaultMapping = require('./boom-mapping') | ||
@@ -32,2 +32,22 @@ /** | ||
/** | ||
* Merge two error mappings | ||
* @param {object} m1 | ||
* @param {object} m2 | ||
* @returns {object} mergedMappings | ||
*/ | ||
const mergeMappings = (m1, m2) => { | ||
const m1Keys = Object.keys(m1) | ||
for (let m1Key of m1Keys) { | ||
if (m2[m1Key]) { | ||
m2[m1Key] = _.union(m2[m1Key], m1[m1Key]) | ||
} else { | ||
m2[m1Key] = m1[m1Key] | ||
} | ||
} | ||
return m2 | ||
} | ||
module.exports = { | ||
@@ -41,2 +61,4 @@ /** | ||
toBoom: (err, customErrors, customMapping) => { | ||
let mapping = defaultMapping | ||
// add custom errors, if any. Overwrites default custom errors if duplicate key is specified | ||
@@ -46,5 +68,5 @@ if (typeof customErrors === 'object') _.assignIn(Errors, customErrors) | ||
// add custom mapping, if any. Overwrites default mapping if duplicate keys are specified | ||
if (typeof customMapping === 'object') _.assignIn(mapping, customMapping) | ||
if (typeof customMapping === 'object') mapping = mergeMappings(defaultMapping, customMapping) | ||
const origErr = _.deepClone(err) | ||
const origErr = _.cloneDeep(err) | ||
const errParams = _.omit(err, 'message') | ||
@@ -55,3 +77,3 @@ | ||
for (let customErr of mapping[boomErr]) { | ||
if (origErr instanceof Errors[customErr]) { | ||
if (Errors[customErr] && origErr instanceof Errors[customErr]) { | ||
return Boom[boomErr](origErr.message, errParams) | ||
@@ -58,0 +80,0 @@ } |
{ | ||
"name": "@c8/errors", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Common errors and their utils used by C8 management", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
5535
98