You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
4 weeks ago
|
/**
|
||
|
*
|
||
|
* @param {Error} error
|
||
|
*/
|
||
|
function parseErrorToStacks(error) {
|
||
|
if (!error || !(error instanceof Error)) {
|
||
|
throw new Error("parseErrorToStacks expects Error object");
|
||
|
}
|
||
|
if (typeof error.stack === "string") {
|
||
|
return error.stack.split("\n").filter(function (stack) {
|
||
|
return stack !== "Error: ".concat(error.message);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @callback ErrorCallback
|
||
|
* @param {ErrorEvent} error
|
||
|
* @returns {void}
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @param {ErrorCallback} callback
|
||
|
*/
|
||
|
function listenToRuntimeError(callback) {
|
||
|
window.addEventListener("error", callback);
|
||
|
return function cleanup() {
|
||
|
window.removeEventListener("error", callback);
|
||
|
};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @callback UnhandledRejectionCallback
|
||
|
* @param {PromiseRejectionEvent} rejectionEvent
|
||
|
* @returns {void}
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @param {UnhandledRejectionCallback} callback
|
||
|
*/
|
||
|
function listenToUnhandledRejection(callback) {
|
||
|
window.addEventListener("unhandledrejection", callback);
|
||
|
return function cleanup() {
|
||
|
window.removeEventListener("unhandledrejection", callback);
|
||
|
};
|
||
|
}
|
||
|
export { listenToRuntimeError, listenToUnhandledRejection, parseErrorToStacks };
|