mirror of
https://github.com/nasa/openmct.git
synced 2024-12-20 21:53:08 +00:00
* Reject promise if telemetryService is undefined * added error and reformatted * added notification and error if provider is missing
This commit is contained in:
parent
70f2fad243
commit
b1ea6efd45
@ -255,8 +255,11 @@ define(
|
||||
// If a telemetryService is not available,
|
||||
// getTelemetryService() should reject, and this should
|
||||
// bubble through subsequent then calls.
|
||||
return telemetryService
|
||||
&& requestTelemetryFromService().then(getRelevantResponse);
|
||||
if (!telemetryService) {
|
||||
return Promise.reject(new Error('TelemetryService is not available'));
|
||||
}
|
||||
|
||||
return requestTelemetryFromService().then(getRelevantResponse);
|
||||
} else {
|
||||
return telemetryAPI.request(domainObject, fullRequest).then(function (telemetry) {
|
||||
return asSeries(telemetry, defaultDomain, defaultRange, sourceMap);
|
||||
|
@ -41,6 +41,9 @@ define(
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
},
|
||||
catch: (rejected) => {
|
||||
return Promise.reject(rejected);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -225,19 +228,6 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
it("warns if no telemetry service can be injected", function () {
|
||||
mockInjector.get.and.callFake(function () {
|
||||
throw "";
|
||||
});
|
||||
|
||||
// Verify precondition
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
|
||||
telemetry.requestData();
|
||||
|
||||
expect(mockLog.info).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("if a new style telemetry source is available, use it", function () {
|
||||
var mockProvider = {};
|
||||
mockTelemetryAPI.findSubscriptionProvider.and.returnValue(mockProvider);
|
||||
|
@ -137,15 +137,17 @@ define([
|
||||
*/
|
||||
function TelemetryAPI(openmct) {
|
||||
this.openmct = openmct;
|
||||
this.requestProviders = [];
|
||||
this.subscriptionProviders = [];
|
||||
this.metadataProviders = [new DefaultMetadataProvider(this.openmct)];
|
||||
|
||||
this.formatMapCache = new WeakMap();
|
||||
this.formatters = new Map();
|
||||
this.limitProviders = [];
|
||||
this.metadataCache = new WeakMap();
|
||||
this.formatMapCache = new WeakMap();
|
||||
this.valueFormatterCache = new WeakMap();
|
||||
this.formatters = new Map();
|
||||
this.metadataProviders = [new DefaultMetadataProvider(this.openmct)];
|
||||
this.noRequestProviderForAllObjects = false;
|
||||
this.requestAbortControllers = new Set();
|
||||
this.requestProviders = [];
|
||||
this.subscriptionProviders = [];
|
||||
this.valueFormatterCache = new WeakMap();
|
||||
}
|
||||
|
||||
TelemetryAPI.prototype.abortAllRequests = function () {
|
||||
@ -314,6 +316,10 @@ define([
|
||||
* telemetry data
|
||||
*/
|
||||
TelemetryAPI.prototype.request = function (domainObject) {
|
||||
if (this.noRequestProviderForAllObjects) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
if (arguments.length === 1) {
|
||||
arguments.length = 2;
|
||||
arguments[1] = {};
|
||||
@ -326,10 +332,13 @@ define([
|
||||
this.standardizeRequestOptions(arguments[1]);
|
||||
const provider = this.findRequestProvider.apply(this, arguments);
|
||||
if (!provider) {
|
||||
return Promise.reject('No provider found');
|
||||
this.requestAbortControllers.delete(abortController);
|
||||
|
||||
return this.handleMissingRequestProvider(domainObject);
|
||||
}
|
||||
|
||||
return provider.request.apply(provider, arguments).catch((rejected) => {
|
||||
return provider.request.apply(provider, arguments)
|
||||
.catch((rejected) => {
|
||||
if (rejected.name !== 'AbortError') {
|
||||
this.openmct.notifications.error('Error requesting telemetry data, see console for details');
|
||||
console.error(rejected);
|
||||
@ -495,6 +504,36 @@ define([
|
||||
return this.formatMapCache.get(metadata);
|
||||
};
|
||||
|
||||
/**
|
||||
* Error Handling: Missing Request provider
|
||||
*
|
||||
* @returns Promise
|
||||
*/
|
||||
TelemetryAPI.prototype.handleMissingRequestProvider = function (domainObject) {
|
||||
this.noRequestProviderForAllObjects = this.requestProviders.every(requestProvider => {
|
||||
const supportsRequest = requestProvider.supportsRequest.apply(requestProvider, arguments);
|
||||
const hasRequestProvider = Object.hasOwn(requestProvider, 'request');
|
||||
|
||||
return supportsRequest && hasRequestProvider;
|
||||
});
|
||||
|
||||
let message = '';
|
||||
let detailMessage = '';
|
||||
if (this.noRequestProviderForAllObjects) {
|
||||
message = 'Missing request providers, see console for details';
|
||||
detailMessage = 'Missing request provider for all request providers';
|
||||
} else {
|
||||
message = 'Missing request provider, see console for details';
|
||||
const { name, identifier } = domainObject;
|
||||
detailMessage = `Missing request provider for domainObject, name: ${name}, identifier: ${JSON.stringify(identifier)}`;
|
||||
}
|
||||
|
||||
this.openmct.notifications.error(message);
|
||||
console.error(detailMessage);
|
||||
|
||||
return Promise.resolve([]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new telemetry data formatter.
|
||||
* @param {Format} format the
|
||||
|
@ -24,7 +24,6 @@ import TelemetryAPI from './TelemetryAPI';
|
||||
const { TelemetryCollection } = require("./TelemetryCollection");
|
||||
|
||||
describe('Telemetry API', function () {
|
||||
const NO_PROVIDER = 'No provider found';
|
||||
let openmct;
|
||||
let telemetryAPI;
|
||||
|
||||
@ -66,6 +65,12 @@ describe('Telemetry API', function () {
|
||||
},
|
||||
type: 'sample-type'
|
||||
};
|
||||
|
||||
openmct.notifications = {
|
||||
error: () => {
|
||||
console.log('sample error notification');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('provides consistent results without providers', function (done) {
|
||||
@ -73,12 +78,11 @@ describe('Telemetry API', function () {
|
||||
|
||||
expect(unsubscribe).toEqual(jasmine.any(Function));
|
||||
|
||||
telemetryAPI.request(domainObject).then(
|
||||
() => {},
|
||||
(error) => {
|
||||
expect(error).toBe(NO_PROVIDER);
|
||||
}
|
||||
).finally(done);
|
||||
telemetryAPI.request(domainObject)
|
||||
.then((data) => {
|
||||
expect(data).toEqual([]);
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
|
||||
it('skips providers that do not match', function (done) {
|
||||
@ -98,8 +102,6 @@ describe('Telemetry API', function () {
|
||||
expect(telemetryProvider.supportsRequest)
|
||||
.toHaveBeenCalledWith(domainObject, jasmine.any(Object));
|
||||
expect(telemetryProvider.request).not.toHaveBeenCalled();
|
||||
}, (error) => {
|
||||
expect(error).toBe(NO_PROVIDER);
|
||||
}).finally(done);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user