diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 57f628ca6d..cd3e17c7f5 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -239,7 +239,7 @@ class ProfilerController $this->profiler->disable(); if (!$profile = $this->profiler->loadProfile($token)) { - return new Response('', 200, array('Content-Type' => 'text/html')); + return new Response('', 404, array('Content-Type' => 'text/html')); } // the toolbar position (top, bottom, normal, or null -- use the configuration) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index c4e3df610e..3830047198 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -9,12 +9,26 @@ request = function(url, onSuccess, onError, payload, options) { var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); options = options || {}; + options.maxTries = options.maxTries || 0; xhr.open(options.method || 'GET', url, true); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.onreadystatechange = function(state) { - if (4 === xhr.readyState && 200 === xhr.status) { + if (4 !== xhr.readyState) { + return null; + } + + if (xhr.status == 404 && options.maxTries > 1) { + setTimeout(function(){ + options.maxTries--; + request(url, onSuccess, onError, payload, options); + }, 500); + + return null; + } + + if (200 === xhr.status) { (onSuccess || noop)(xhr); - } else if (4 === xhr.readyState && xhr.status != 200) { + } else { (onError || noop)(xhr); } }; @@ -75,6 +89,7 @@ (onSuccess || noop)(xhr, el); }, function(xhr) { (onError || noop)(xhr, el); }, + '', options ); } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig index f3d5a71347..fb098ae91b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig @@ -34,7 +34,8 @@ if (xhr.status !== 0) { confirm('An error occurred while loading the web debug toolbar (' + xhr.status + ': ' + xhr.statusText + ').\n\nDo you want to open the profiler?') && (window.location = '{{ path("_profiler", { "token": token }) }}'); } - } + }, + {'maxTries': 5} ); })(); /*]]>*/