Skip to content

Commit

Permalink
Handle importing invalid types (elastic#10666)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
w33ble authored Mar 4, 2017
1 parent 08b9535 commit 46c9605
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,20 @@ uiModules.get('apps/management')
return service.get()
.then(function (obj) {
obj.id = doc._id;
return obj.applyESResp(doc).then(() => obj.save({ confirmOverwrite : !overwriteAll }));
});
})
.then(refreshIndex)
.then(refreshData)
.catch(notify.error);
return obj.applyESResp(doc)
.then(() => {
return obj.save({ confirmOverwrite : !overwriteAll });
})
.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);
});
})
.then(refreshIndex)
.then(refreshData)
.catch(notify.error);
});
});
};

Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/vis/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,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({},
Expand Down

0 comments on commit 46c9605

Please sign in to comment.