diff --git a/src/js/ads.js b/src/js/ads.js index ee41e6d..bb2ac91 100644 --- a/src/js/ads.js +++ b/src/js/ads.js @@ -43,6 +43,7 @@ class VideoAds { }); googleSdkScript.addEventListener('error', (e) => { + this.reportError(e); reject(e); }); } @@ -208,6 +209,7 @@ class VideoAds { this.adsManager.start(); } catch (adError) { // An error may be thrown if there was a problem with the VAST response. + this.reportError(adError); this.video.videoEl.play(); } } @@ -319,7 +321,16 @@ class VideoAds { } } - adErrorHandler() { + reportError(error) { + document.body.dispatchEvent(new CustomEvent('oErrors.log', { bubbles: true, detail: { error: error } })); + } + + adErrorHandler(adError) { + + // convert the Google Ad error to a JS one + const message = `${adError.getErrorCode()}, ${adError.getType()}, ${adError.getMessage()}, ${adError.getVastErrorCode()}`; + this.reportError(new Error(message)); + this.adsManager && this.adsManager.destroy(); this.video.containerEl.removeChild(this.adContainerEl); if (this.overlayEl) {