91a8c13aa0
In https://github.com/hashicorp/consul/pull/8065 we attempted to reduce the amount of times that the UI requests the discovery chain endpoint when connect is disabled on a datacenter. Currently we can only tell if connect is disabled on a datacenter by detecting a 500 error from a connect related endpoint. In the above PR we mistakenly returned from a catch instead of rethrowing the error, which meant that when a none 500 error was caught the discovery chain data would be removed. Whilst at first glance this doens't seem like a big problem due to the endpoint erroring, but we also receive a 0 error when we abort endpoints during blocking queries. This means that in certain cases we can remove cached data for the discovery chain and then delay reloading it via a blocking query. This PR replaces the return with a throw, which means that everything is dealt with correctly via the blocking query error detection/logic.
32 lines
1 KiB
JavaScript
32 lines
1 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import { get, set } from '@ember/object';
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
const modelName = 'discovery-chain';
|
|
const ERROR_MESH_DISABLED = 'Connect must be enabled in order to use this endpoint';
|
|
export default RepositoryService.extend({
|
|
dcs: service('repository/dc'),
|
|
getModelName: function() {
|
|
return modelName;
|
|
},
|
|
findBySlug: function(slug, dc, nspace, configuration = {}) {
|
|
const datacenter = this.dcs.peekOne(dc);
|
|
if (datacenter !== null && !get(datacenter, 'MeshEnabled')) {
|
|
return Promise.resolve();
|
|
}
|
|
return this._super(...arguments).catch(e => {
|
|
const code = get(e, 'errors.firstObject.status');
|
|
const body = get(e, 'errors.firstObject.detail').trim();
|
|
switch (code) {
|
|
case '500':
|
|
if (datacenter !== null && body === ERROR_MESH_DISABLED) {
|
|
set(datacenter, 'MeshEnabled', false);
|
|
}
|
|
return;
|
|
default:
|
|
throw e;
|
|
}
|
|
});
|
|
},
|
|
});
|