whoops 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/index.js +7 -6
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
- An easy way to create qualified errors.
|
|
12
12
|
- Using the standard `Error` interface in browser and NodeJS.
|
|
13
13
|
- Attach extra information, being flexible with whatever user case.
|
|
14
|
+
- Less than 50 lines (~500 bytes)
|
|
14
15
|
|
|
15
16
|
This library is a compromise to provide a clean API for use `Error` native class.
|
|
16
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -5,12 +5,13 @@ function createErrorClass (ErrorClass) {
|
|
|
5
5
|
class CustomError extends ErrorClass {
|
|
6
6
|
constructor (raw = {}) {
|
|
7
7
|
super(raw)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const { message, ...props } = Object.assign(
|
|
9
|
+
{},
|
|
10
|
+
defaults,
|
|
11
|
+
typeof raw === 'string' ? { message: raw } : raw
|
|
12
|
+
)
|
|
13
|
+
Object.keys(props).forEach(key => (this[key] = props[key]))
|
|
14
|
+
if (message) this.description = typeof message === 'function' ? message(props) : message
|
|
14
15
|
this.message = this.code ? `${this.code}, ${this.description}` : this.description
|
|
15
16
|
this.name = name || ErrorClass.name
|
|
16
17
|
}
|