[Telemetry] Implement Abort Request (#4504)

* Add a requestAbortController for the telemetryAPI and trigger an abort of all requests on navigation via the router.
* Check for the rejection and make sure it's not an abort error to show the error
This commit is contained in:
Khalid Adil
2021-12-06 14:14:14 -06:00
committed by GitHub
parent 8eba3a81f3
commit 749e84611e
5 changed files with 82 additions and 4 deletions

View File

@ -144,8 +144,14 @@ define([
this.metadataCache = new WeakMap();
this.formatMapCache = new WeakMap();
this.valueFormatterCache = new WeakMap();
this.requestAbortControllers = new Set();
}
TelemetryAPI.prototype.abortAllRequests = function () {
this.requestAbortControllers.forEach((controller) => controller.abort());
this.requestAbortControllers.clear();
};
/**
* Return Custom String Formatter
*
@ -312,6 +318,10 @@ define([
arguments[1] = {};
}
const abortController = new AbortController();
arguments[1].signal = abortController.signal;
this.requestAbortControllers.add(abortController);
this.standardizeRequestOptions(arguments[1]);
const provider = this.findRequestProvider.apply(this, arguments);
if (!provider) {
@ -319,10 +329,14 @@ define([
}
return provider.request.apply(provider, arguments).catch((rejected) => {
this.openmct.notifications.error('Error requesting telemetry data, see console for details');
console.error(rejected);
if (rejected.name !== 'AbortError') {
this.openmct.notifications.error('Error requesting telemetry data, see console for details');
console.error(rejected);
}
return Promise.reject(rejected);
}).finally(() => {
this.requestAbortControllers.delete(abortController);
});
};