diff --git a/src/adUnit/VastAdUnit.js b/src/adUnit/VastAdUnit.js index 08cb8b76..32f8ee9e 100644 --- a/src/adUnit/VastAdUnit.js +++ b/src/adUnit/VastAdUnit.js @@ -33,7 +33,10 @@ class VastAdUnit extends VideoAdUnit { case errorEvt: { this.error = data; this.errorCode = this.error && this.error.code ? this.error.code : 405; - this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error)); + this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error, { + adUnit: this, + vastChain: this.vastChain + })); this[_protected].finish(); break; } diff --git a/src/adUnit/VideoAdUnit.js b/src/adUnit/VideoAdUnit.js index 26a4504f..ca020e78 100644 --- a/src/adUnit/VideoAdUnit.js +++ b/src/adUnit/VideoAdUnit.js @@ -277,7 +277,7 @@ class VideoAdUnit extends Emitter { * * @throws if ad unit is finished. * - * @param {Function} callback - will be called on ad unit error passing the Error instance as the only argument if available. + * @param {Function} callback - will be called on ad unit error passing the Error instance and an object with the adUnit and the {@link VastChain}. */ onError (callback) { if (typeof callback !== 'function') { diff --git a/src/adUnit/VpaidAdUnit.js b/src/adUnit/VpaidAdUnit.js index 9c568dc2..792ea0b9 100644 --- a/src/adUnit/VpaidAdUnit.js +++ b/src/adUnit/VpaidAdUnit.js @@ -119,7 +119,10 @@ class VpaidAdUnit extends VideoAdUnit { this.error = vpaidGeneralError(payload); this.errorCode = this.error.code; - this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error)); + this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error, { + adUnit: this, + vastChain: this.vastChain + })); this[_protected].finish(); diff --git a/src/adUnit/__tests__/VastAdUnit.spec.js b/src/adUnit/__tests__/VastAdUnit.spec.js index 940ce1d6..d159ba68 100644 --- a/src/adUnit/__tests__/VastAdUnit.spec.js +++ b/src/adUnit/__tests__/VastAdUnit.spec.js @@ -303,7 +303,10 @@ describe('VastAdUnit', () => { type: errorEvt }); expect(onErrorCallback).toHaveBeenCalledTimes(1); - expect(onErrorCallback).toHaveBeenCalledWith(adUnit.error); + expect(onErrorCallback).toHaveBeenCalledWith(adUnit.error, { + adUnit, + vastChain + }); }); test('start must select a mediaFile and update the src and the assetUri', async () => { @@ -492,7 +495,10 @@ describe('VastAdUnit', () => { videoElement.dispatchEvent(new Event('error')); expect(callback).toHaveBeenCalledTimes(1); - expect(callback).toHaveBeenCalledWith(mediaError); + expect(callback).toHaveBeenCalledWith(mediaError, { + adUnit, + vastChain + }); expect(adUnit.error).toBe(mediaError); expect(adUnit.errorCode).toBe(405); expect(adUnit.isFinished()).toBe(true); diff --git a/src/adUnit/__tests__/VpaidAdUnit.spec.js b/src/adUnit/__tests__/VpaidAdUnit.spec.js index 176d61fb..b32a2bc4 100644 --- a/src/adUnit/__tests__/VpaidAdUnit.spec.js +++ b/src/adUnit/__tests__/VpaidAdUnit.spec.js @@ -693,7 +693,10 @@ describe('VpaidAdUnit', () => { } catch (error) { expect(error).toBe(handshakeVersionError); expect(callback).toHaveBeenCalledTimes(1); - expect(callback).toHaveBeenCalledWith(handshakeVersionError); + expect(callback).toHaveBeenCalledWith(handshakeVersionError, { + adUnit, + vastChain: adUnit.vastChain + }); } }); @@ -709,10 +712,12 @@ describe('VpaidAdUnit', () => { adUnit.creativeAd.emit(adError); expect(callback).toHaveBeenCalledTimes(1); - expect(callback).toHaveBeenCalledWith(expect.any(Error)); expect(callback).toHaveBeenCalledWith(expect.objectContaining({ message: 'VPAID general error' - })); + }), { + adUnit, + vastChain: adUnit.vastChain + }); }); }); }); diff --git a/src/runner/__tests__/runWaterfall.spec.js b/src/runner/__tests__/runWaterfall.spec.js index 9a2ea73e..48ef6926 100644 --- a/src/runner/__tests__/runWaterfall.spec.js +++ b/src/runner/__tests__/runWaterfall.spec.js @@ -311,8 +311,16 @@ describe('runWaterfall', () => { await deferred.promise; expect(onError).toHaveBeenCalledTimes(3); - expect(onError).toHaveBeenCalledWith(runError); - expect(onError).toHaveBeenCalledWith(requestError); + expect(onError).toHaveBeenCalledWith(runError, { + adUnit: undefined, + vastChain: vastAdChain + }); + + expect(onError).toHaveBeenCalledWith(requestError, { + adUnit: undefined, + vastChain: undefined + }); + expect(requestAd).toHaveBeenCalledTimes(1); expect(requestAd).toHaveBeenCalledWith(adTag, expect.any(Object)); expect(requestNextAd).toHaveBeenCalledTimes(2); @@ -340,10 +348,16 @@ describe('runWaterfall', () => { const simulateAdUnitError = adUnit.onError.mock.calls[0][0]; const mockError = new Error('mock error'); - simulateAdUnitError(mockError); + simulateAdUnitError(mockError, { + adUnit, + vastChain: vastAdChain + }); expect(onError).toHaveBeenCalledTimes(1); - expect(onError).toHaveBeenCalledWith(mockError); + expect(onError).toHaveBeenCalledWith(mockError, { + adUnit, + vastChain: adUnit.vastChain + }); }); }); diff --git a/src/runner/runWaterfall.js b/src/runner/runWaterfall.js index c29dc040..d5c3972e 100644 --- a/src/runner/runWaterfall.js +++ b/src/runner/runWaterfall.js @@ -104,7 +104,10 @@ const waterfall = async (fetchVastChain, placeholder, options, isCanceled) => { }); } - onError(error); + onError(error, { + adUnit, + vastChain + }); if (vastChain && !isCanceled()) { if (runEpoch) { @@ -143,7 +146,7 @@ const waterfall = async (fetchVastChain, placeholder, options, isCanceled) => { * Defaults to `5`. * @param {runWaterfall~onAdReady} [options.onAdReady] - will be called once the ad is ready with the ad unit. * @param {runWaterfall~onAdStart} [options.onAdStart] - will be called once the ad starts with the ad unit. - * @param {runWaterfall~onError} [options.onError] - will be called if there is an error with the video ad with the error instance. + * @param {runWaterfall~onError} [options.onError] - will be called if there is an error with the video ad with the error instance and an obj with the {@link VastChain} and the ad unit if it exists. * @param {runWaterfall~onRunFinish} [options.onRunFinish] - will be called whenever the ad run finishes. * @param {boolean} [options.viewability] - if true it will pause the ad whenever is not visible for the viewer. * Defaults to `false` @@ -223,6 +226,9 @@ export default runWaterfall; * * @callback RunWaterfall~onError * @param {Error} error - the ad unit error. + * @param {Object} [data] - Data object that will contain: + * @param {VastChain} [data.vastChain] - The {@link VastChain} that caused the error. + * @param {VideoAdUnit} [data.adUnit] - Ad unit instance it can be a {@link VastAdUnit} or a {@link VpaidAdUnit}. Will only be added if the vastChain had an ad. */ /**