Skip to content

Commit

Permalink
applied suggested fixes:
Browse files Browse the repository at this point in the history
added error handling on promise catch,
moved fetch block out of XHR block,
fixed method detect,
matched url against excluded urls
  • Loading branch information
ivoba committed Sep 29, 2016
1 parent af9225d commit e080ca1
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,25 @@
}
{% if excluded_ajax_paths is defined %}
if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
if (window.fetch) {
var oldFetch = window.fetch;
window.fetch = function () {
var promise = oldFetch.apply(null, arguments);
if (window.fetch) {
var oldFetch = window.fetch;
window.fetch = function () {
var promise = oldFetch.apply(null, arguments);
if (!arguments[0].match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
var method = 'GET';
if (arguments[1] && arguments[1].method !== undefined) {
method = arguments[1].method;
}
var stackElement = {
loading: true,
error: false,
url: arguments[0],
method: arguments[1].method,
method: method,
start: new Date()
};
requestStack.push(stackElement);
promise.then(function (r) {
stackElement.duration = new Date() - stackElement.start;
Expand All @@ -256,11 +263,17 @@
stackElement.profile = r.headers.get('x-debug-token');
stackElement.profilerUrl = r.headers.get('x-debug-token-link');
Sfjs.renderAjaxRequests();
}).catch(function(err) {
stackElement.loading = false;
stackElement.error = true;
});
Sfjs.renderAjaxRequests();
return promise;
};
}
}
return promise;
};
}
if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
var proxied = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
Expand Down

0 comments on commit e080ca1

Please sign in to comment.