10000 applied suggested fixes: · symfony/symfony@c4c33f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4c33f7

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 c4c33f7

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,27 @@
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 }}))) {
243+
242244
var promise = oldFetch.apply(null, arguments);
245+
246+
var method = 'GET';
247+
if(arguments[1].method !== undefined){
248+
method = arguments[1].method;
249+
}
250+
243251
var stackElement = {
244252
loading: true,
245253
error: false,
246254
url: arguments[0],
247-
method: arguments[1].method,
255+
method: method,
248256
start: new Date()
249257
};
258+
250259
requestStack.push(stackElement);
251260
promise.then(function (r) {
252261
stackElement.duration = new Date() - stackElement.start;
@@ -256,11 +265,17 @@
256265
stackElement.profile = r.headers.get('x-debug-token');
257266
stackElement.profilerUrl = r.headers.get('x-debug-token-link');
258267
Sfjs.renderAjaxRequests();
268+
}).catch(function(err) {
269+
stackElement.loading = false;
270+
stackElement.error = true;
259271
});
260272
Sfjs.renderAjaxRequests();
273+
261274
return promise;
262-
};
263-
}
275+
}
276+
};
277+
}
278+
if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
264279
var proxied = XMLHttpRequest.prototype.open;
265280
266281
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {

0 commit comments

Comments
 (0)
0