mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-03-06 18:09:10 +00:00
51 lines
1.0 KiB
TypeScript
51 lines
1.0 KiB
TypeScript
|
export default class ErrorInterceptor {
|
||
|
private static instance: ErrorInterceptor;
|
||
|
public running;
|
||
|
|
||
|
constructor() {
|
||
|
this.running = [];
|
||
|
}
|
||
|
|
||
|
public static getInstance(): ErrorInterceptor {
|
||
|
if (!ErrorInterceptor.instance) {
|
||
|
ErrorInterceptor.instance = new ErrorInterceptor();
|
||
|
}
|
||
|
return ErrorInterceptor.instance;
|
||
|
}
|
||
|
|
||
|
clear() {
|
||
|
this.running = [];
|
||
|
}
|
||
|
|
||
|
add(obj) {
|
||
|
this.running.push(obj);
|
||
|
}
|
||
|
|
||
|
remove(obj) {
|
||
|
const index = this.running.indexOf(obj);
|
||
|
if (index !== -1) {
|
||
|
this.running.splice(index, 1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
process.on("uncaughtException", (error) => {
|
||
|
console.log(error);
|
||
|
const toStop = ErrorInterceptor.getInstance().running;
|
||
|
for (const elm of toStop) {
|
||
|
elm.rejectAll(error);
|
||
|
}
|
||
|
global.testFailed = true;
|
||
|
});
|
||
|
|
||
|
// Global error handler for unhandled promise rejections
|
||
|
process.on("unhandledRejection", (reason, promise) => {
|
||
|
console.log(reason);
|
||
|
const toStop = ErrorInterceptor.getInstance().running;
|
||
|
for (const elm of toStop) {
|
||
|
elm.rejectAll(reason);
|
||
|
}
|
||
|
global.testFailed = true;
|
||
|
});
|