quantal-errors
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -1,4 +0,1 @@ | ||
/** | ||
* Created by dman on 03/07/2017. | ||
*/ | ||
'use strict' | ||
@@ -8,4 +5,33 @@ const utils = require('./utils') | ||
/** | ||
* Maps an err to boom errors | ||
// will map custom errors to boom errors | ||
// This should be the last middleware in the chain | ||
/** | ||
* For example | ||
* | ||
* customErrors = { | ||
* MyCustomError: createError('MyCustomError') | ||
* } | ||
* customMappings = { | ||
* badRequest: ['MyCustomError'] | ||
* } | ||
* @param customErrors | ||
* @param customMappings | ||
* @returns {function(*=, *, *, *)} | ||
*/ | ||
module.exports = (customErrors, customMappings) => { | ||
return (err, req, res, next) => { | ||
// will map custom errors to boom errors | ||
// This should be the last middleware in the chain | ||
/** | ||
* For example | ||
* | ||
* customErrors = { | ||
* MyCustomError: createError('MyCustomError') | ||
* } | ||
* customMappings = { | ||
* badRequest: ['MyCustomError'] | ||
* } | ||
*/ | ||
const boomErr = utils.toBoom(err, customErrors, customMappings) | ||
@@ -12,0 +38,0 @@ res.status(boomErr.output.statusCode).json(_.omit(boomErr.output.payload, ['params'])) |
@@ -94,5 +94,14 @@ 'use strict' | ||
* Translates application error to boom error based defined mapping or default mapping | ||
* For example | ||
* | ||
* customErrors = { | ||
* MyCustomError: createError('MyCustomError') | ||
* } | ||
* customMapping = { | ||
* badRequest: ['MyCustomError'] | ||
* } | ||
* | ||
* @param {Error} err Error to convert | ||
* @param {object} customErrors | ||
* @param {object} customMapping | ||
* @param {object} customErrors - hash / object that of custom errors | ||
* @param {object} customMapping - mappings between custome errors and boom errors | ||
* @return {Error} Boom error | ||
@@ -99,0 +108,0 @@ */ |
{ | ||
"name": "quantal-errors", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Common errors and their utils", | ||
@@ -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
17903
389