-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
26 lines (25 loc) · 865 Bytes
/
main.js
File metadata and controls
26 lines (25 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {
ensureCorrectClass,
ponyfillCause,
setErrorName,
} from 'error-class-utils'
// Create an error class with a specific `name`.
// We do not call `Error.captureStackTrace(this, CustomErrorClass)` because:
// - It is V8 specific
// - And on V8 (unlike in some browsers like Firefox), `Error.stack`
// automatically omits the stack lines from custom error constructors
// - Also, this would force child classes to also use
// `Error.captureStackTrace()`
/* eslint-disable fp/no-this */
export default function errorCustomClass(name) {
const CustomErrorClass = class extends Error {
constructor(message, parameters) {
super(message, parameters)
ensureCorrectClass(this, new.target)
ponyfillCause(this, parameters)
}
}
setErrorName(CustomErrorClass, name)
return CustomErrorClass
}
/* eslint-enable fp/no-this */