From 9da4f4a3aee7d1c13fc24b1384bb4e244d2b96a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 26 Jul 2017 08:32:18 +0200 Subject: [PATCH] phone: keep track of failed ajax calls and reload if too many (#17793) --- welco/static/js/welco.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/welco/static/js/welco.js b/welco/static/js/welco.js index 02c3229..9ac903d 100644 --- a/welco/static/js/welco.js +++ b/welco/static/js/welco.js @@ -527,17 +527,31 @@ $(function() { }); if ($('.source-phone').length) { + var failed_ajax_calls = 0; + + function handle_ajax_error() { + failed_ajax_calls += 1; + if (failed_ajax_calls == 10) { + window.location.reload(); + } + } + function check_active_call() { var active_call_url = $('[data-active-call-url]').data('active-call-url'); $.ajax({url: active_call_url, dataType: 'json', success: function(response) { + failed_ajax_calls = 0; if (response.active === false) { $(' (terminé)').appendTo($('div.phonecall.active h1')); window.setTimeout(check_calls, 1000); } else { window.setTimeout(check_active_call, 5000); } + }, + error: function() { + handle_ajax_error(); + window.setTimeout(check_active_call, 5000 + failed_ajax_calls * 1000); } }); } @@ -550,6 +564,7 @@ $(function() { $.ajax({url: current_calls_url, dataType: 'json', success: function(response) { + failed_ajax_calls = 0; if (response.data.calls.length != 0) { /* got a call */ var caller = response.data.calls[0].caller; @@ -566,8 +581,9 @@ $(function() { } window.setTimeout(check_calls, 1000); }, - error: function() { - window.setTimeout(check_calls, 1000); + error: function(error) { + handle_ajax_error(); + window.setTimeout(check_calls, 1000 + failed_ajax_calls * 1000); } }); }