@c8/errors
Advanced tools
+0
-0
@@ -0,0 +0,0 @@ 'use strict' |
| module.exports = { | ||
| entityTooLarge: ['FileTooLargeError'], | ||
| unsupportedMediaType: ['TypeError'], | ||
| badRequest: ['PurseAlreadyExists'], | ||
| notFound: ['NotFoundError'] | ||
| forbidden: ['PermissionDeniedError'], | ||
| notFound: ['NotFoundError'], | ||
| conflict: ['AlreadyExistsError'], | ||
| serverTimeout: ['TimeoutError'], | ||
| badRequest: ['InvalidInputError', 'SizeError'], | ||
| notImplemented: ['NotImplementedError'] | ||
| } | ||
| // NotUpdatedError | ||
| // NotRemovedError |
+5
-26
@@ -6,33 +6,12 @@ 'use strict' | ||
| module.exports = { | ||
| FileTooLargeError: createError('FileTooLargeError'), | ||
| SizeError: createError('SizeError'), | ||
| TypeError: createError('TypeError'), | ||
| ReadError: createError('ReadError'), | ||
| InvalidIdError: createError('InvalidIdError'), | ||
| TokenNotFoundError: createError('TokenNotFoundError'), | ||
| TokenTypeError: createError('TokenTypeError'), | ||
| EmailAlreadyRegisteredError: createError('EmailAlreadyRegisteredError'), | ||
| PermissionDeniedError: createError('PermissionDeniedError'), | ||
| NotFoundError: createError('NotFoundError'), | ||
| NotUpdatedError: createError('NotUpdatedError'), | ||
| NotRemovedError: createError('NotRemovedError'), | ||
| UserActivatedError: createError('UserActivatedError'), | ||
| UserDeActivatedError: createError('UserDeActivatedError'), | ||
| UserPendingError: createError('UserPendingError'), | ||
| InvalidDataError: createError('InvalidDataError'), | ||
| RecordCreationError: createError('RecordCreationError'), | ||
| InvalidTokenError: createError('InvalidTokenError'), | ||
| TokenExpiredOrRevokedError: createError('ExpiredOrRevokedTokenError'), | ||
| NullOrUndefinedReferenceError: createError('NullOrUndefinedReferenceError'), | ||
| PasswordError: createError('PasswordError'), | ||
| ReactivationPeriodNotElapsedError: createError('ReactivationPeriodNotElapsedError'), | ||
| PermissionNotFoundError: createError('PermissionNotFoundError'), | ||
| InvalidEmail: createError('InvalidEmail'), | ||
| InvalidPasswordError: createError('InvalidPasswordError'), | ||
| InvalidLoginAttempt: createError('InvalidLoginAttempt'), | ||
| ActivationCodeGenerationError: createError('ActivationCodeGenerationError'), | ||
| ActivationCodeError: createError('ActivationCodeError'), | ||
| UnauthorizedError: createError('UnauthorizedError'), | ||
| ConnectionRefused: createError('ConnectionRefused'), | ||
| // ppl-marketplace | ||
| PurseAlreadyExists: createError('PurseAlreadyExists') | ||
| InvalidInputError: createError('InvalidInputError'), | ||
| TimeoutError: createError('TimeoutError'), | ||
| AlreadyExistsError: createError('AlreadyExistsError') | ||
| } |
+37
-15
@@ -6,4 +6,27 @@ 'use strict' | ||
| const Errors = require('./errors') | ||
| const defaultBoomMapping = require('./boom-mapping') | ||
| const mapping = require('./boom-mapping') | ||
| /** | ||
| Native errors in Node.js: | ||
| ========================= | ||
| <EvalError> : thrown when a call to eval() fails. | ||
| <SyntaxError> : thrown in response to improper JavaScript language syntax. | ||
| <RangeError> : thrown when a value is not within an expected range | ||
| <ReferenceError> : thrown when using undefined variables | ||
| <TypeError> : thrown when passing arguments of the wrong type | ||
| <URIError> : thrown when a global URI handling function is misused. | ||
| // We probably just want to convert these to standard 500 | ||
| if ( | ||
| origErr instanceof EvalError || | ||
| origErr instanceof SyntaxError || | ||
| origErr instanceof RangeError || | ||
| origErr instanceof ReferenceError || | ||
| origErr instanceof TypeError || | ||
| origErr instanceof URIError | ||
| ) { | ||
| return Boom.badImplementation(origErr.message, errParams) | ||
| } | ||
| */ | ||
| module.exports = { | ||
@@ -16,26 +39,25 @@ /** | ||
| */ | ||
| toBoom: (err, mapping) => { | ||
| if (typeof mapping !== 'object') mapping = defaultBoomMapping | ||
| toBoom: (err, customErrors, customMapping) => { | ||
| // add custom errors, if any. Overwrites default custom errors if duplicate key is specified | ||
| if (typeof customErrors === 'object') _.assignIn(Errors, customErrors) | ||
| let errData = _.cloneDeep(err) | ||
| delete errData.message | ||
| // add custom mapping, if any. Overwrites default mapping if duplicate keys are specified | ||
| if (typeof customMapping === 'object') _.assignIn(mapping, customMapping) | ||
| const origErr = _.deepClone(err) | ||
| const errParams = _.omit(err, 'message') | ||
| let boomError = (() => { | ||
| for (let boomErr of Object.keys(mapping)) { | ||
| for (let serviceErr of mapping[boomErr]) { | ||
| if (err instanceof Errors[serviceErr]) { | ||
| return Boom[boomErr](err.message, errData) | ||
| for (let customErr of mapping[boomErr]) { | ||
| if (origErr instanceof Errors[customErr]) { | ||
| return Boom[boomErr](origErr.message, errParams) | ||
| } | ||
| } | ||
| } | ||
| })() | ||
| })() || Boom.wrap(origErr) // defaults to HTTP 500 status | ||
| if (!boomError) { | ||
| boomError = Boom.wrap(err) | ||
| boomError.data = errData | ||
| } | ||
| // Make err.data publicly available so we can send extra intel like custom error codes. | ||
| // err.data can be filled in the last parameter of any Boom function. | ||
| boomError.output.payload.params = boomError.data | ||
| boomError.output.payload.params = errParams | ||
@@ -42,0 +64,0 @@ return boomError |
+1
-1
| { | ||
| "name": "@c8/errors", | ||
| "version": "0.0.10", | ||
| "version": "0.1.0", | ||
| "description": "Common errors and their utils used by C8 management", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+0
-0
@@ -0,0 +0,0 @@ # @c8/errors |
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
85
4.94%5260
-4.22%