Fix formatting of 'Saved object not found' error toast. (#21421) (#21496)

This commit is contained in:
CJ Cenizal 2018-07-31 10:43:24 -07:00 committed by GitHub
parent b62148c35e
commit a772aa8c8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 13 deletions

View file

@ -211,7 +211,9 @@ export function SavedObjectProvider(Promise, Private, Notifier, confirmModalProm
this.applyESResp = (resp) => {
this._source = _.cloneDeep(resp._source);
if (resp.found != null && !resp.found) throw new SavedObjectNotFound(esType, this.id);
if (resp.found != null && !resp.found) {
throw new SavedObjectNotFound(esType, this.id);
}
const meta = resp._source.kibanaSavedObjectMeta || {};
delete resp._source.kibanaSavedObjectMeta;

View file

@ -95,12 +95,10 @@ export function IndexPatternProvider(Private, config, Promise, confirmModalPromi
function updateFromElasticSearch(indexPattern, response, forceFieldRefresh = false) {
if (!response.found) {
const markdownSaveId = indexPattern.id.replace('*', '%2A');
throw new SavedObjectNotFound(
type,
indexPattern.id,
kbnUrl.eval('#/management/kibana/index?id={{id}}&name=', { id: markdownSaveId })
'#/management/kibana/index',
);
}

View file

@ -18,9 +18,11 @@
*/
import React from 'react';
import { MarkdownSimple } from 'ui/markdown';
import { toastNotifications } from 'ui/notify';
import { SavedObjectNotFound } from '../errors';
import { uiModules } from '../modules';
import { toastNotifications } from 'ui/notify';
uiModules.get('kibana/url')
.service('redirectWhenMissing', function (Private) { return Private(RedirectWhenMissingProvider); });
@ -39,22 +41,26 @@ export function RedirectWhenMissingProvider($location, kbnUrl, Promise) {
mapping = { '*': mapping };
}
return function (err) {
return function (error) {
// if this error is not "404", rethrow
const savedObjectNotFound = err instanceof SavedObjectNotFound;
const unknownVisType = err.message.indexOf('Invalid type') === 0;
const savedObjectNotFound = error instanceof SavedObjectNotFound;
const unknownVisType = error.message.indexOf('Invalid type') === 0;
if (unknownVisType) {
err.savedObjectType = 'visualization';
error.savedObjectType = 'visualization';
} else if (!savedObjectNotFound) {
throw err;
throw error;
}
let url = mapping[err.savedObjectType] || mapping['*'];
let url = mapping[error.savedObjectType] || mapping['*'];
if (!url) url = '/';
url += (url.indexOf('?') >= 0 ? '&' : '?') + `notFound=${err.savedObjectType}`;
url += (url.indexOf('?') >= 0 ? '&' : '?') + `notFound=${error.savedObjectType}`;
toastNotifications.addWarning({
title: 'Saved object is missing',
text: <MarkdownSimple>{error.message}</MarkdownSimple>,
});
toastNotifications.addWarning(err.message);
kbnUrl.redirect(url);
return Promise.halt();
};