mirror of
				https://github.com/pagefaultgames/pokerogue.git
				synced 2025-10-31 16:35:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			50 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;
 | |
| });
 |