Handle importing invalid types (#10666)

* show service errors but resolve promise

By handling service failures explicitely, the error doesn't bubble up the promise chain, so tasks
that have to happen after it, like refreshing the index and data, still happen, and the UI will
be in sync with the data in the .kibana index

* throw error on invalid saved object type

* append useful info to the type error message
This commit is contained in:
Joe Fleming 2017-03-03 17:45:22 -07:00 committed by Joe Fleming
parent c9dacfcf60
commit d79e68e823
2 changed files with 16 additions and 3 deletions

View file

@ -180,8 +180,14 @@ uiModules.get('apps/management')
return service.get().then(function (obj) {
obj.id = doc._id;
return obj.applyESResp(doc).then(function () {
return obj.applyESResp(doc)
.then(function () {
return obj.save({ confirmOverwrite : true });
})
.catch((err) => {
// swallow errors here so that the remaining promise chain executes
err.message = `Importing ${obj.title} (${obj.id}) failed: ${err.message}`;
notify.error(err);
});
});
})

View file

@ -84,8 +84,15 @@ export default function VisFactory(Notifier, Private) {
Vis.prototype.setState = function (state) {
this.title = state.title || '';
this.type = state.type || this.type;
if (_.isString(this.type)) this.type = visTypes.byName[this.type];
const type = state.type || this.type;
if (_.isString(type)) {
this.type = visTypes.byName[type];
if (!this.type) {
throw new Error(`Invalid type "${type}"`);
}
} else {
this.type = type;
}
this.listeners = _.assign({}, state.listeners, this.type.listeners);
this.params = _.defaults({},