8000 applied suggested fixes: · symfony/symfony@0e72c2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e72c2e

Browse files
committed
applied suggested fixes:
added error handling on promise catch, moved fetch block out of XHR block, fixed method detect, matched url against excluded urls
1 parent af9225d commit 0e72c2e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,26 @@
235235
}
236236
237237
{% if excluded_ajax_paths is defined %}
238-
if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
239-
if (window.fetch) {
240-
var oldFetch = window.fetch;
241-
window.fetch = function () {
238+
239+
if (window.fetch) {
240+
var oldFetch = window.fetch;
241+
window.fetch = function () {
242+
if (!arguments[0].match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
242243
var promise = oldFetch.apply(null, arguments);
244+
245+
var method = 'GET';
246+
if (arguments[1] && arguments[1].method !== undefined) {
247+
method = arguments[1].method;
248+
}
249+
243250
var stackElement = {
244251
loading: true,
245252
error: false,
246253
url: arguments[0],
247-
method: arguments[1].method,
254+
method: method,
248255
start: new Date()
249256
};
257+
250258
requestStack.push(stackElement);
251259
promise.then(function (r) {
252260
stackElement.duration = new Date() - stackElement.start;
@@ -256,11 +264,17 @@
256264
stackElement.profile = r.headers.get('x-debug-token');
257265
stackElement.profilerUrl = r.headers.get('x-debug-token-link');
258266
Sfjs.renderAjaxRequests();
267+
}).catch(function(err) {
268+
stackElement.loading = false;
269+
stackElement.error = true;
259270
});
260271
Sfjs.renderAjaxRequests();
272+
261273
return promise;
262-
};
263-
}
274+
}
275+
};
276+
}
277+
if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
264278
var proxied = XMLHttpRequest.prototype.open;
265279
266280
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {

0 commit comments

Comments
 (0)
0