Skip to content

Commit

Permalink
Merge pull request #1370 from appsembler/bugfix/ENG-97-catch-and-retr…
Browse files Browse the repository at this point in the history
…y-yt-api-errs

ENG-97 Try/Catch around more of the onYouTubeIframeAPIReady code to retry
  • Loading branch information
bryanlandia authored Sep 14, 2023
2 parents 7a8ccab + 6bb24a6 commit 6e7a3ef
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions common/lib/xmodule/xmodule/js/src/video/01_initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function(VideoPlayer, i18n, moment, _) {

_youtubeApiDeferred = null,
_oldOnYouTubeIframeAPIReady;
const setupOnYouTubeIframeAPIReadyMaxCalls=3;
const setupOnYouTubeIframeAPIReadyMaxCalls=5;

Initialize.prototype = methodsDict;

Expand Down Expand Up @@ -174,30 +174,31 @@ function(VideoPlayer, i18n, moment, _) {
throw new Error('Too many OnYouTubeIframeAPIReady retries after TypeError...giving up.');
}

_oldOnYouTubeIframeAPIReady = window.onYouTubeIframeAPIReady || undefined;
try {
_oldOnYouTubeIframeAPIReady = window.onYouTubeIframeAPIReady || undefined;

window.onYouTubeIframeAPIReady = function() {
window.onYouTubeIframeAPIReady.resolve();
};
window.onYouTubeIframeAPIReady = function() {
window.onYouTubeIframeAPIReady.resolve();
};

try {
window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve;
window.onYouTubeIframeAPIReady.done = _youtubeApiDeferred.done;

if (_oldOnYouTubeIframeAPIReady) {
window.onYouTubeIframeAPIReady.done(_oldOnYouTubeIframeAPIReady);
}
} catch (e) {
console.error('Error while trying to resolve the Deferred object responsible for calling OnYouTubeIframeAPIReady callbacks.');
console.error('window.onYouTubeIframeAPIReady is ' + window.onYouTubeIframeAPIReady);
console.error(e);
if (e instanceof TypeError) {
setupOnYouTubeIframeAPIReady(); // Try again up to defined max calls.
setTimeout(setupOnYouTubeIframeAPIReady, 500); // Try again up to defined max calls.
}
else {
throw e;
}
}
window.onYouTubeIframeAPIReady.done = _youtubeApiDeferred.done;

if (_oldOnYouTubeIframeAPIReady) {
window.onYouTubeIframeAPIReady.done(_oldOnYouTubeIframeAPIReady);
}
};

// If a Deferred object hasn't been created yet, create one now. It will
Expand Down

0 comments on commit 6e7a3ef

Please sign in to comment.