error-ninja
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -16,6 +16,14 @@ 'use strict'; | ||
const CustomUriError = createErrorClass(`CustomUriError`); | ||
const VideoStreamError = createErrorClass(`VideoStreamError`); | ||
const FatalError = createErrorClass(`FatalError`); | ||
// Create one error constructor at a time. | ||
// const CustomUriError = createErrorClass(`CustomUriError`); | ||
// const VideoStreamError = createErrorClass(`VideoStreamError`); | ||
// const FatalError = createErrorClass(`FatalError`); | ||
// Or create all error constructors at once. | ||
const { CustomUriError, VideoStreamError, FatalError } = createErrorClass([ | ||
`CustomUriError`, | ||
`VideoStreamError`, | ||
`FatalError`, | ||
]); | ||
/** | ||
@@ -22,0 +30,0 @@ * Faux function to demonstrate how native errors (e.g. an undefined variable) and error ninjas (new CustomUriError) get |
@@ -10,3 +10,3 @@ { | ||
"name": "error-ninja", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Allows us to pre-define error types and error messages in each module.", | ||
@@ -13,0 +13,0 @@ "keywords": [ |
@@ -31,9 +31,26 @@ 'use strict'; | ||
/** | ||
* Creates and returns a new error class. | ||
* Creates and returns a new error class. Can optionally accept an array of class names to create multiple at a time. | ||
* | ||
* @param {String} errorName - The class name for the new error. | ||
* @returns {ErrorClass} - The newly created error class. | ||
* @param {String|Array<String>} input - The class name for the new error, or an array of class names. | ||
* @returns {ErrorClass|dictionary<ErrorClass>} - The newly created error class, or a dictionary of error classes. | ||
*/ | ||
function createErrorClass (errorName) { | ||
function createErrorClass (input) { | ||
let errorName; | ||
// Cope with creating multiple error classes at once. | ||
if (Array.isArray(input)) { | ||
const output = input.reduce((acc, item) => { | ||
acc[item] = createErrorClass(item); | ||
return acc; | ||
}, {}); | ||
return output; | ||
} | ||
// Or just create a single error class. | ||
else { | ||
errorName = input; | ||
} | ||
/** | ||
@@ -40,0 +57,0 @@ * Create a new class of error. |
25184
360