diff options
| author | Omar Roth <omarroth@protonmail.com> | 2019-06-15 10:08:06 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@protonmail.com> | 2019-06-15 10:09:32 -0500 |
| commit | 552f616305809d111f7540cbea93f89fad3d0760 (patch) | |
| tree | d078614fb388923ab347c05491de4e34ae10d3f6 /assets/js/embed.js | |
| parent | a3164177f8e7e3d323006e08755230f850a5fdd9 (diff) | |
| download | invidious-552f616305809d111f7540cbea93f89fad3d0760.tar.gz invidious-552f616305809d111f7540cbea93f89fad3d0760.tar.bz2 invidious-552f616305809d111f7540cbea93f89fad3d0760.zip | |
Fix retry on timeout for AJAX requests
Diffstat (limited to 'assets/js/embed.js')
| -rw-r--r-- | assets/js/embed.js | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/assets/js/embed.js b/assets/js/embed.js index 283bc06d..1f742864 100644 --- a/assets/js/embed.js +++ b/assets/js/embed.js @@ -1,5 +1,5 @@ -function get_playlist(plid, timeouts = 1) { - if (timeouts >= 10) { +function get_playlist(plid, retries = 5) { + if (retries <= 0) { console.log('Failed to pull playlist'); return; } @@ -18,7 +18,6 @@ function get_playlist(plid, timeouts = 1) { xhr.responseType = 'json'; xhr.timeout = 20000; xhr.open('GET', plid_url, true); - xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { @@ -51,10 +50,17 @@ function get_playlist(plid, timeouts = 1) { } } + xhr.onerror = function () { + console.log('Pulling playlist failed... ' + retries + '/5'); + setTimeout(function () { get_playlist(plid, retries - 1) }, 1000); + } + xhr.ontimeout = function () { - console.log('Pulling playlist timed out... ' + timeouts + '/10'); - get_playlist(plid, timeouts++); + console.log('Pulling playlist failed... ' + retries + '/5'); + get_playlist(plid, retries - 1); } + + xhr.send(); } if (video_data.plid) { |
