2020-06-10 15:07:06 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { get, set } from '@ember/object';
|
2019-12-17 19:27:28 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
|
|
|
|
const modelName = 'discovery-chain';
|
2020-06-10 15:07:06 +00:00
|
|
|
const ERROR_MESH_DISABLED = 'Connect must be enabled in order to use this endpoint';
|
2019-12-17 19:27:28 +00:00
|
|
|
export default RepositoryService.extend({
|
2020-06-10 15:07:06 +00:00
|
|
|
dcs: service('repository/dc'),
|
2019-12-17 19:27:28 +00:00
|
|
|
getModelName: function() {
|
|
|
|
return modelName;
|
|
|
|
},
|
2020-06-10 15:07:06 +00:00
|
|
|
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:
|
2020-07-01 09:21:15 +00:00
|
|
|
throw e;
|
2020-06-10 15:07:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2019-12-17 19:27:28 +00:00
|
|
|
});
|