Comparing version 4.1.8 to 5.0.0
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/Kikobeats/whoops", | ||
"version": "4.1.8", | ||
"version": "5.0.0", | ||
"main": "src/index.js", | ||
@@ -37,6 +37,2 @@ "author": { | ||
], | ||
"dependencies": { | ||
"clean-stack": "~3.0.0", | ||
"mimic-fn": "~3.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -51,3 +47,2 @@ "@commitlint/cli": "latest", | ||
"github-generate-release": "latest", | ||
"mocha": "latest", | ||
"nano-staged": "latest", | ||
@@ -76,3 +71,3 @@ "should": "latest", | ||
"release:tags": "git push --follow-tags origin HEAD:master", | ||
"test": "c8 mocha" | ||
"test": "c8 node --test" | ||
}, | ||
@@ -79,0 +74,0 @@ "license": "MIT", |
'use strict' | ||
const createExtendError = require('./create-extend-error') | ||
const createError = require('./create-error') | ||
function createErrorClass (ErrorClass) { | ||
return (name, defaults) => { | ||
class CustomError extends ErrorClass { | ||
constructor (raw = {}) { | ||
super(raw) | ||
const createErrorClass = ErrorClass => (className, props) => { | ||
const errorClass = createError(className || ErrorClass.name) | ||
return createExtendError(errorClass, props) | ||
const { message, ...props } = typeof raw === 'string' ? { message: raw } : raw | ||
const mergedProps = Object.assign({}, defaults, props) | ||
Object.keys(mergedProps).forEach(key => (this[key] = mergedProps[key])) | ||
if (message) this.description = typeof message === 'function' ? message(this) : message | ||
this.message = this.code ? `${this.code}, ${this.description}` : this.description | ||
this.name = name || ErrorClass.name | ||
} | ||
} | ||
// Function to create an instance, allowing use without `new` | ||
function CustomErrorFactory (props) { | ||
return new CustomError(props) | ||
} | ||
// Ensure the function's name matches the class name for consistency | ||
Object.defineProperty(CustomErrorFactory, 'name', { | ||
value: name || ErrorClass.name, | ||
writable: false | ||
}) | ||
// Make `instanceof` checks work with both the class and factory | ||
CustomErrorFactory.prototype = CustomError.prototype | ||
return CustomErrorFactory | ||
} | ||
} | ||
@@ -10,0 +36,0 @@ |
0
14
9862
4
35
- Removedclean-stack@~3.0.0
- Removedmimic-fn@~3.1.0
- Removedclean-stack@3.0.1(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedmimic-fn@3.1.0(transitive)