- current_analysis_xhr = $.ajax({
- url: backend_url + "?ims=" + ims + "&unique=" + unique
- }).done(function(data, textstatus, xhr) {
- process_update_response(data, textstatus, xhr);
-
- // Next update.
- if (!backend_url.match(/history/)) {
- var timeout = 100;
- current_analysis_request_timer = setTimeout(function() { request_update(); }, timeout);
- }
- }).fail(function(jqXHR, textStatus, errorThrown) {
- document.body.style.opacity = null;
- if (textStatus === "abort") {
- // Aborted because we are switching backends. Abandon and don't retry,
- // because another one is already started for us.
- } else {
- // Backend error or similar. Wait ten seconds, then try again.
- current_analysis_request_timer = setTimeout(function() { request_update(); }, 10000);
- }
- });
+ let handle_err = () => {
+ // Backend error or similar. Wait ten seconds, then try again.
+ current_analysis_request_timer = setTimeout(function() { request_update(); }, 10000);
+ };
+
+ current_analysis_xhr = new AbortController();
+ const signal = current_analysis_xhr.signal;
+ fetch(backend_url + "?ims=" + ims + "&unique=" + unique, { signal })
+ .then((response) => response.json().then(data => ({ok: response.ok, headers: response.headers, json: data}))) // ick
+ .then((obj) => {
+ if (!obj.ok) {
+ handle_err();
+ return;
+ }
+
+ if (delay_ms === 0) {
+ process_update_response(obj.json, obj.headers);
+ } else {
+ setTimeout(function() { process_update_response(obj.json, obj.headers); }, delay_ms);
+ }
+
+ // Next update.
+ if (!backend_url.match(/history/)) {
+ var timeout = 100;
+ current_analysis_request_timer = setTimeout(function() { request_update(); }, timeout);
+ }
+ })
+ .catch((err) => {
+ if (err.name === 'AbortError') {
+ // Aborted because we are switching backends. Abandon and don't retry,
+ // because another one is already started for us.
+ } else {
+ console.log(err);
+ handle_err(err);
+ }
+ })
+ .finally(() => {
+ // Display.
+ document.body.style.opacity = null;
+ })
+