callErrorHandlerAndReject = function callErrorHandlerAndReject(err, onRejected) {
        var _this = this;

        /**
         * only call error handler if there is any and if error has bubbled up
         */
        if (!this || this.depth !== 0 || options.onError.length === 0) {
            return reject.call(this, err, onRejected);
        }

        return new _promise2.default(function (resolve, reject) {
            return _promise2.default.all(options.onError.map(function (fn) {
                if (!global.wdioSync) {
                    return fn.call(_this, err);
                }

                return new _promise2.default(function (resolve) {
                    return global.wdioSync(fn, resolve).call(_this, err);
                });
            })).then(resolve, reject);
        }).then(function () {
            return reject.call(_this, err, onRejected);
        });
    }
middleware to call on error handler in wdio mode