mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
[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:
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user