main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import ApiDOMAggregateError from "./ApiDOMAggregateError.mjs";
|
---|
| 2 | class ApiDOMError extends Error {
|
---|
| 3 | static [Symbol.hasInstance](instance) {
|
---|
| 4 | // we want to ApiDOMAggregateError to act as if ApiDOMError was its superclass
|
---|
| 5 | return super[Symbol.hasInstance](instance) || Function.prototype[Symbol.hasInstance].call(ApiDOMAggregateError, instance);
|
---|
| 6 | }
|
---|
| 7 | constructor(message, options) {
|
---|
| 8 | super(message, options);
|
---|
| 9 | this.name = this.constructor.name;
|
---|
| 10 | if (typeof message === 'string') {
|
---|
| 11 | this.message = message;
|
---|
| 12 | }
|
---|
| 13 | if (typeof Error.captureStackTrace === 'function') {
|
---|
| 14 | Error.captureStackTrace(this, this.constructor);
|
---|
| 15 | } else {
|
---|
| 16 | this.stack = new Error(message).stack;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * This needs to stay here until our minimum supported version of Node.js is >= 16.9.0.
|
---|
| 21 | * Node.js is >= 16.9.0 supports error causes natively.
|
---|
| 22 | */
|
---|
| 23 | if (options != null && typeof options === 'object' && Object.hasOwn(options, 'cause') && !('cause' in this)) {
|
---|
| 24 | const {
|
---|
| 25 | cause
|
---|
| 26 | } = options;
|
---|
| 27 | this.cause = cause;
|
---|
| 28 | if (cause instanceof Error && 'stack' in cause) {
|
---|
| 29 | this.stack = `${this.stack}\nCAUSE: ${cause.stack}`;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | export default ApiDOMError; |
---|
Note:
See
TracBrowser
for help on using the repository browser.