-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.js
31 lines (26 loc) · 905 Bytes
/
errors.js
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
27
28
29
30
31
import { errorToEvent } from './assets/error.js';
if (! globalThis.hasOwnProperty('AggregateError')) {
globalThis.AggregateError = class AggregateError extends Error {
constructor(errors, message) {
if (typeof message === 'undefined') {
super(errors);
this.errors = [];
} else {
super(message);
this.errors = errors;
}
}
};
}
if (! (globalThis.reportError instanceof Function)) {
globalThis.reportError = function reportError(error) {
globalThis.dispatchEvent(errorToEvent(error));
};
}
if (! (Error.isError instanceof Function)) {
// @see https://github.com/tc39/proposal-is-error/blob/main/polyfill.js
const toStr = Function.bind.call(Function.call, Object.prototype.toString);
Error.isError = function isError(arg) {
return arg instanceof Error || (typeof arg === 'object' && toStr(arg) === '[object Error]' && arg[Symbol.toStringTag] === undefined);
};
}