浏览代码

Added better error handling in the action queue.

Maciej Bukowski 5 年之前
父节点
当前提交
fa807ea45a
共有 1 个文件被更改,包括 17 次插入1 次删除
  1. 17 1
      packages/ckeditor5-watchdog/src/contextwatchdog.js

+ 17 - 1
packages/ckeditor5-watchdog/src/contextwatchdog.js

@@ -170,6 +170,15 @@ export default class ContextWatchdog extends Watchdog {
 
 					this._watchdogs.set( itemName, watchdog );
 
+					// Enqueue the internal watchdog errors within the main queue.
+					watchdog.on( 'error', () => {
+						if ( watchdog._shouldRestart() ) {
+							this._actionQueue.enqueue( () => new Promise( res => {
+								watchdog.once( 'restart', () => res() );
+							} ) );
+						}
+					} );
+
 					return watchdog.create( item.sourceElementOrData, item.config, this._context );
 				} else {
 					throw new Error( `Not supported item type: '${ item.type }'.` );
@@ -441,7 +450,14 @@ class ActionQueue {
 
 				return this._handleActions( res, rej );
 			} )
-			.catch( err => rej( err ) );
+			.catch( err => {
+				rej( err );
+
+				this._queuedActions.shift();
+
+				// Run pending actions even if an error has happened to unlock the queue.
+				return this._handleActions( res, rej );
+			} );
 	}
 }