export class ProtractorErrorHandler { constructor(private readonly handlers: Map Promise | void> = new Map()) { } async executeIfHandled(error: Error, action: () => Promise | T): Promise { if (! this.handlers.has(error.name)) { throw error; } await this.handlers.get(error.name)(error); return action(); } setHandlerFor(errorType: string, handler: (error: Error) => Promise | void): void { this.handlers.set(errorType, handler); } unsetHandlerFor(errorType: string): void { this.handlers.delete(errorType); } }