Skip to content

Commit 17fbd64

Browse files
authored
Merge pull request #142 from MailOnline/next-release
Next release
2 parents 4beb2f7 + 2f60ea8 commit 17fbd64

File tree

7 files changed

+51
-14
lines changed

7 files changed

+51
-14
lines changed

src/adUnit/VastAdUnit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class VastAdUnit extends VideoAdUnit {
3333
case errorEvt: {
3434
this.error = data;
3535
this.errorCode = this.error && this.error.code ? this.error.code : 405;
36-
this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error));
36+
this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error, {
37+
adUnit: this,
38+
vastChain: this.vastChain
39+
}));
3740
this[_protected].finish();
3841
break;
3942
}

src/adUnit/VideoAdUnit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class VideoAdUnit extends Emitter {
277277
*
278278
* @throws if ad unit is finished.
279279
*
280-
* @param {Function} callback - will be called on ad unit error passing the Error instance as the only argument if available.
280+
* @param {Function} callback - will be called on ad unit error passing the Error instance and an object with the adUnit and the {@link VastChain}.
281281
*/
282282
onError (callback) {
283283
if (typeof callback !== 'function') {

src/adUnit/VpaidAdUnit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ class VpaidAdUnit extends VideoAdUnit {
119119
this.error = vpaidGeneralError(payload);
120120
this.errorCode = this.error.code;
121121

122-
this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error));
122+
this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error, {
123+
adUnit: this,
124+
vastChain: this.vastChain
125+
}));
123126

124127
this[_protected].finish();
125128

src/adUnit/__tests__/VastAdUnit.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ describe('VastAdUnit', () => {
303303
type: errorEvt
304304
});
305305
expect(onErrorCallback).toHaveBeenCalledTimes(1);
306-
expect(onErrorCallback).toHaveBeenCalledWith(adUnit.error);
306+
expect(onErrorCallback).toHaveBeenCalledWith(adUnit.error, {
307+
adUnit,
308+
vastChain
309+
});
307310
});
308311

309312
test('start must select a mediaFile and update the src and the assetUri', async () => {
@@ -492,7 +495,10 @@ describe('VastAdUnit', () => {
492495

493496
videoElement.dispatchEvent(new Event('error'));
494497
expect(callback).toHaveBeenCalledTimes(1);
495-
expect(callback).toHaveBeenCalledWith(mediaError);
498+
expect(callback).toHaveBeenCalledWith(mediaError, {
499+
adUnit,
500+
vastChain
501+
});
496502
expect(adUnit.error).toBe(mediaError);
497503
expect(adUnit.errorCode).toBe(405);
498504
expect(adUnit.isFinished()).toBe(true);

src/adUnit/__tests__/VpaidAdUnit.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,10 @@ describe('VpaidAdUnit', () => {
693693
} catch (error) {
694694
expect(error).toBe(handshakeVersionError);
695695
expect(callback).toHaveBeenCalledTimes(1);
696-
expect(callback).toHaveBeenCalledWith(handshakeVersionError);
696+
expect(callback).toHaveBeenCalledWith(handshakeVersionError, {
697+
adUnit,
698+
vastChain: adUnit.vastChain
699+
});
697700
}
698701
});
699702

@@ -709,10 +712,12 @@ describe('VpaidAdUnit', () => {
709712
adUnit.creativeAd.emit(adError);
710713

711714
expect(callback).toHaveBeenCalledTimes(1);
712-
expect(callback).toHaveBeenCalledWith(expect.any(Error));
713715
expect(callback).toHaveBeenCalledWith(expect.objectContaining({
714716
message: 'VPAID general error'
715-
}));
717+
}), {
718+
adUnit,
719+
vastChain: adUnit.vastChain
720+
});
716721
});
717722
});
718723
});

src/runner/__tests__/runWaterfall.spec.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,16 @@ describe('runWaterfall', () => {
311311
await deferred.promise;
312312

313313
expect(onError).toHaveBeenCalledTimes(3);
314-
expect(onError).toHaveBeenCalledWith(runError);
315-
expect(onError).toHaveBeenCalledWith(requestError);
314+
expect(onError).toHaveBeenCalledWith(runError, {
315+
adUnit: undefined,
316+
vastChain: vastAdChain
317+
});
318+
319+
expect(onError).toHaveBeenCalledWith(requestError, {
320+
adUnit: undefined,
321+
vastChain: undefined
322+
});
323+
316324
expect(requestAd).toHaveBeenCalledTimes(1);
317325
expect(requestAd).toHaveBeenCalledWith(adTag, expect.any(Object));
318326
expect(requestNextAd).toHaveBeenCalledTimes(2);
@@ -340,10 +348,16 @@ describe('runWaterfall', () => {
340348
const simulateAdUnitError = adUnit.onError.mock.calls[0][0];
341349
const mockError = new Error('mock error');
342350

343-
simulateAdUnitError(mockError);
351+
simulateAdUnitError(mockError, {
352+
adUnit,
353+
vastChain: vastAdChain
354+
});
344355

345356
expect(onError).toHaveBeenCalledTimes(1);
346-
expect(onError).toHaveBeenCalledWith(mockError);
357+
expect(onError).toHaveBeenCalledWith(mockError, {
358+
adUnit,
359+
vastChain: adUnit.vastChain
360+
});
347361
});
348362
});
349363

src/runner/runWaterfall.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ const waterfall = async (fetchVastChain, placeholder, options, isCanceled) => {
104104
});
105105
}
106106

107-
onError(error);
107+
onError(error, {
108+
adUnit,
109+
vastChain
110+
});
108111

109112
if (vastChain && !isCanceled()) {
110113
if (runEpoch) {
@@ -143,7 +146,7 @@ const waterfall = async (fetchVastChain, placeholder, options, isCanceled) => {
143146
* Defaults to `5`.
144147
* @param {runWaterfall~onAdReady} [options.onAdReady] - will be called once the ad is ready with the ad unit.
145148
* @param {runWaterfall~onAdStart} [options.onAdStart] - will be called once the ad starts with the ad unit.
146-
* @param {runWaterfall~onError} [options.onError] - will be called if there is an error with the video ad with the error instance.
149+
* @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.
147150
* @param {runWaterfall~onRunFinish} [options.onRunFinish] - will be called whenever the ad run finishes.
148151
* @param {boolean} [options.viewability] - if true it will pause the ad whenever is not visible for the viewer.
149152
* Defaults to `false`
@@ -223,6 +226,9 @@ export default runWaterfall;
223226
*
224227
* @callback RunWaterfall~onError
225228
* @param {Error} error - the ad unit error.
229+
* @param {Object} [data] - Data object that will contain:
230+
* @param {VastChain} [data.vastChain] - The {@link VastChain} that caused the error.
231+
* @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.
226232
*/
227233

228234
/**

0 commit comments

Comments
 (0)