Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Moved KbnError base class ⇒ kibana_utils (#45532) #45809

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Moved KbnError base class ⇒ kibana_utils (#45532)
* moved errors base class to kibana_utils

* Fixed tests for ui/errors imports

* fixed test path

* Restored Request Failure resp field

* Restored savedObjectType and savedObjectId

* simplified Error class extension

* updated constructors
Liza Katz committed Sep 16, 2019
commit 56ba6602ab7c4b3289f6fb4ba9ffb18a89c0b21e
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';

function getParams(filter, indexPattern) {
const type = 'geo_bounding_box';
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';

function getParams(filter, indexPattern) {
const type = 'geo_polygon';
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';

function isScriptedPhrase(filter) {
const value = _.get(filter, ['script', 'script', 'params', 'value']);
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/

import { has, get } from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';


function isScriptedRange(filter) {
12 changes: 5 additions & 7 deletions src/legacy/core_plugins/data/public/index_patterns/errors.ts
Original file line number Diff line number Diff line change
@@ -19,16 +19,15 @@

/* eslint-disable */

// @ts-ignore
import { KbnError } from 'ui/errors';
import { KbnError } from '../../../../../plugins/kibana_utils/public';

/**
* when a mapping already exists for a field the user is attempting to add
* @param {String} name - the field name
*/
export class IndexPatternAlreadyExists extends KbnError {
constructor(name: string) {
super(`An index pattern of "${name}" already exists`, IndexPatternAlreadyExists);
super(`An index pattern of "${name}" already exists`);
}
}

@@ -40,8 +39,7 @@ export class IndexPatternMissingIndices extends KbnError {
const defaultMessage = "IndexPattern's configured pattern does not match any indices";

super(
message && message.length ? `No matching indices found: ${message}` : defaultMessage,
IndexPatternMissingIndices
message && message.length ? `No matching indices found: ${message}` : defaultMessage
);
}
}
@@ -51,7 +49,7 @@ export class IndexPatternMissingIndices extends KbnError {
*/
export class NoDefinedIndexPatterns extends KbnError {
constructor() {
super('Define at least one index pattern to continue', NoDefinedIndexPatterns);
super('Define at least one index pattern to continue');
}
}

@@ -60,6 +58,6 @@ export class NoDefinedIndexPatterns extends KbnError {
*/
export class NoDefaultIndexPattern extends KbnError {
constructor() {
super('Please specify a default index pattern', NoDefaultIndexPattern);
super('Please specify a default index pattern');
}
}
Original file line number Diff line number Diff line change
@@ -21,8 +21,7 @@ import { defaults, pluck, last, get } from 'lodash';
import { IndexedArray } from 'ui/indexed_array';
import { IndexPattern } from './index_pattern';

// @ts-ignore
import { DuplicateField } from 'ui/errors';
import { DuplicateField } from '../../../../../../plugins/kibana_utils/public';
// @ts-ignore
import mockLogStashFields from '../../../../../../fixtures/logstash_fields';
// @ts-ignore
Original file line number Diff line number Diff line change
@@ -24,14 +24,13 @@ import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import React from 'react';
import chrome from 'ui/chrome';
// @ts-ignore
import { SavedObjectNotFound, DuplicateField } from 'ui/errors';
// @ts-ignore
import { fieldFormats } from 'ui/registry/field_formats';
// @ts-ignore
import { expandShorthand } from 'ui/utils/mapping_setup';
import { toastNotifications } from 'ui/notify';
import { findObjectByTitle } from 'ui/saved_objects';
import { SavedObjectsClientContract } from 'src/core/public';
import { SavedObjectNotFound, DuplicateField } from '../../../../../../plugins/kibana_utils/public';

import { IndexPatternMissingIndices } from '../errors';
import { Field, FieldList, FieldType } from '../fields';
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ import dashboardTemplate from './dashboard_app.html';
import dashboardListingTemplate from './listing/dashboard_listing_ng_wrapper.html';

import { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';
import { InvalidJSONProperty, SavedObjectNotFound } from 'ui/errors';
import { InvalidJSONProperty, SavedObjectNotFound } from '../../../../../plugins/kibana_utils/public';
import { FeatureCatalogueRegistryProvider, FeatureCatalogueCategory } from 'ui/registry/feature_catalogue';
import { SavedObjectsClientProvider } from 'ui/saved_objects';
import { recentlyAccessed } from 'ui/persisted_log';
Original file line number Diff line number Diff line change
@@ -35,19 +35,6 @@ jest.mock('../components/header', () => ({
Header: () => 'Header',
}));

jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));

jest.mock('ui/chrome', () => ({
addBasePath: () => '',
getInjected: () => ['index-pattern', 'visualization', 'dashboard', 'search'],
Original file line number Diff line number Diff line change
@@ -24,19 +24,6 @@ import { Flyout } from '../flyout';

jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));

jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));

jest.mock('../../../../../lib/import_file', () => ({
importFile: jest.fn(),
}));
Original file line number Diff line number Diff line change
@@ -22,19 +22,6 @@ import { shallowWithIntl } from 'test_utils/enzyme_helpers';

jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));

jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));

jest.mock('ui/chrome', () => ({
addBasePath: () => ''
}));
Original file line number Diff line number Diff line change
@@ -24,19 +24,6 @@ import { keyCodes } from '@elastic/eui/lib/services';

jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));

jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));

jest.mock('ui/chrome', () => ({
addBasePath: () => ''
}));
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ import {
saveObject,
} from '../resolve_saved_objects';

jest.mock('ui/errors', () => ({

jest.mock('../../../../../../../../../plugins/kibana_utils/public', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
@@ -36,6 +37,7 @@ jest.mock('ui/errors', () => ({
}
},
}));
import { SavedObjectNotFound } from '../../../../../../../../../plugins/kibana_utils/public';

describe('resolveSavedObjects', () => {
describe('resolveSavedObjects', () => {
@@ -81,7 +83,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@@ -95,7 +96,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@@ -109,7 +109,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@@ -175,7 +174,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'search',
});
@@ -189,7 +187,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@@ -204,7 +201,6 @@ describe('resolveSavedObjects', () => {
savedSearchId: '1',
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
* under the License.
*/

import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../../plugins/kibana_utils/public';
import { i18n } from '@kbn/i18n';

async function getSavedObject(doc, services) {
3 changes: 1 addition & 2 deletions src/legacy/ui/public/agg_types/param_types/field.ts
Original file line number Diff line number Diff line change
@@ -20,8 +20,7 @@
// @ts-ignore
import { i18n } from '@kbn/i18n';
import { AggConfig } from '../../vis';
// @ts-ignore
import { SavedObjectNotFound } from '../../errors';
import { SavedObjectNotFound } from '../../../../../plugins/kibana_utils/public';
import { FieldParamEditor } from '../../vis/editors/default/controls/field';
import { BaseParamType } from './base';
import { toastNotifications } from '../../notify';
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiSpacer } from '@elastic/eui';
import { toastNotifications } from '../../notify';
import { RequestFailure } from '../../errors';
import { RequestFailure } from './errors';
import { RequestStatus } from './req_status';
import { SearchError } from '../search_strategy/search_error';
import { ShardFailureOpenModalButton } from './components/shard_failure_open_modal_button';
34 changes: 34 additions & 0 deletions src/legacy/ui/public/courier/fetch/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { KbnError } from '../../../../../plugins/kibana_utils/public';
/**
* Request Failure - When an entire multi request fails
* @param {Error} err - the Error that came back
* @param {Object} resp - optional HTTP response
*/
export class RequestFailure extends KbnError {
public resp: any;
constructor(err: any, resp?: any) {
err = err || false;
super(`Request to Elasticsearch failed: ${JSON.stringify(resp || err.message)}`);

this.resp = resp;
}
}
249 changes: 0 additions & 249 deletions src/legacy/ui/public/errors.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import sinon from 'sinon';
import noDigestPromises from 'test_utils/no_digest_promises';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import { PersistedStateError } from '../../errors';
import { PersistedStateError } from '../errors';
import '..';

let PersistedState;
26 changes: 26 additions & 0 deletions src/legacy/ui/public/persisted_state/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { KbnError } from '../../../../plugins/kibana_utils/public';

export class PersistedStateError extends KbnError {
constructor() {
super('Error with the persisted state');
}
}
3 changes: 2 additions & 1 deletion src/legacy/ui/public/persisted_state/persisted_state.js
Original file line number Diff line number Diff line change
@@ -25,9 +25,10 @@

import _ from 'lodash';
import toPath from 'lodash/internal/toPath';
import { PersistedStateError } from '../errors';
import { PersistedStateError } from './errors';
import { SimpleEmitter } from '../utils/simple_emitter';


function prepSetParams(key, value, path) {
// key must be the value, set the entire state using it
if (_.isUndefined(value) && (_.isPlainObject(key) || path.length > 0)) {
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ import BluebirdPromise from 'bluebird';
import { SavedObjectProvider } from '../saved_object';
import StubIndexPatternProv from 'test_utils/stub_index_pattern';
import { SavedObjectsClientProvider } from '../saved_objects_client_provider';
import { InvalidJSONProperty } from '../../errors';
import { InvalidJSONProperty } from '../../../../../plugins/kibana_utils/public';

const getConfig = cfg => cfg;

3 changes: 2 additions & 1 deletion src/legacy/ui/public/saved_objects/saved_object.js
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@
import angular from 'angular';
import _ from 'lodash';

import { InvalidJSONProperty, SavedObjectNotFound } from '../errors';

import { InvalidJSONProperty, SavedObjectNotFound } from '../../../../plugins/kibana_utils/public';
import { expandShorthand } from '../utils/mapping_setup';

import { SearchSourceProvider } from '../courier/search_source';
2 changes: 1 addition & 1 deletion src/legacy/ui/public/url/redirect_when_missing.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { MarkdownSimple } from '../../../core_plugins/kibana_react/public/markdown';
import { toastNotifications } from 'ui/notify';
import { SavedObjectNotFound } from '../errors';
import { SavedObjectNotFound } from '../../../../plugins/kibana_utils/public';
import { uiModules } from '../modules';

uiModules.get('kibana/url')
56 changes: 56 additions & 0 deletions src/legacy/ui/public/vislib/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* eslint-disable max-classes-per-file */

import { KbnError } from '../../../../plugins/kibana_utils/public';

export class VislibError extends KbnError {
constructor(message: string) {
super(message);
}

displayToScreen(handler: any) {
handler.error(this.message);
}
}

export class InvalidLogScaleValues extends VislibError {
constructor() {
super('Values less than 1 cannot be displayed on a log scale');
}
}

export class ContainerTooSmall extends VislibError {
constructor() {
super('This container is too small to render the visualization');
}
}

export class PieContainsAllZeros extends VislibError {
constructor() {
super('No results displayed because all values equal 0.');
}
}

export class NoResults extends VislibError {
constructor() {
super('No results found');
}
}
2 changes: 1 addition & 1 deletion src/legacy/ui/public/vislib/lib/_error_handler.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { ContainerTooSmall } from '../../errors';
import { ContainerTooSmall } from '../errors';

/**
* Common errors shared between constructors
2 changes: 1 addition & 1 deletion src/legacy/ui/public/vislib/lib/axis/axis.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ import { AxisTitle } from './axis_title';
import { AxisLabels } from './axis_labels';
import { AxisScale } from './axis_scale';
import { AxisConfig } from './axis_config';
import { VislibError } from '../../../errors';
import { VislibError } from '../../errors';

export class Axis extends ErrorHandler {
constructor(visConfig, axisConfigArgs) {
3 changes: 2 additions & 1 deletion src/legacy/ui/public/vislib/lib/axis/axis_scale.js
Original file line number Diff line number Diff line change
@@ -21,9 +21,10 @@ import d3 from 'd3';
import _ from 'lodash';
import moment from 'moment';

import { InvalidLogScaleValues } from '../../../errors';
import { InvalidLogScaleValues } from '../../errors';
import { timeTicks } from './time_ticks';


export class AxisScale {
constructor(axisConfig, visConfig) {
this.axisConfig = axisConfig;
2 changes: 1 addition & 1 deletion src/legacy/ui/public/vislib/lib/handler.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
import d3 from 'd3';
import _ from 'lodash';
import MarkdownIt from 'markdown-it';
import { NoResults } from '../../errors';
import { NoResults } from '../errors';
import { Binder } from '../../binder';
import { Layout } from './layout/layout';
import { ChartTitle } from './chart_title';
4 changes: 2 additions & 2 deletions src/legacy/ui/public/vislib/vis.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import _ from 'lodash';
import d3 from 'd3';
import { EventEmitter } from 'events';
import chrome from '../chrome';
import { KbnError } from '../errors';
import { VislibError } from './errors';
import { VisConfig } from './lib/vis_config';
import { Handler } from './lib/handler';
import { setHierarchicalTooltipFormatter } from '../vis/components/tooltip/_hierarchical_tooltip_formatter';
@@ -98,7 +98,7 @@ export function VislibVisProvider(Private) {
this.handler[method]();
} catch (error) {

if (error instanceof KbnError) {
if (error instanceof VislibError) {
error.displayToScreen(this.handler);
} else {
throw error;
2 changes: 1 addition & 1 deletion src/legacy/ui/public/vislib/visualizations/pie_chart.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import d3 from 'd3';
import _ from 'lodash';
import $ from 'jquery';
import numeral from 'numeral';
import { PieContainsAllZeros, ContainerTooSmall } from '../../errors';
import { PieContainsAllZeros, ContainerTooSmall } from '../errors';
import { Chart } from './_chart';
import { truncateLabel } from '../components/labels/truncate_labels';

Original file line number Diff line number Diff line change
@@ -18,47 +18,10 @@
*/

import expect from '@kbn/expect';
import {
RequestFailure,
FetchFailure,
VersionConflict,
MappingConflict,
RestrictedMapping,
CacheWriteFailure,
FieldNotFoundInCache,
DuplicateField,
SavedObjectNotFound,
PersistedStateError,
VislibError,
ContainerTooSmall,
InvalidWiggleSelection,
PieContainsAllZeros,
InvalidLogScaleValues,
StackedBarChartConfig,
NoResults,
KbnError
} from '../errors';
import { DuplicateField, SavedObjectNotFound, KbnError } from './errors';

describe('ui/errors', () => {
const errors = [
new RequestFailure('an error', { }),
new FetchFailure({ }),
new VersionConflict({ }),
new MappingConflict({ }),
new RestrictedMapping('field', 'indexPattern'),
new CacheWriteFailure(),
new FieldNotFoundInCache('aname'),
new DuplicateField('dupfield'),
new SavedObjectNotFound('dashboard', '123'),
new PersistedStateError(),
new VislibError('err'),
new ContainerTooSmall(),
new InvalidWiggleSelection(),
new PieContainsAllZeros(),
new InvalidLogScaleValues(),
new StackedBarChartConfig('err'),
new NoResults()
];
describe('errors', () => {
const errors = [new DuplicateField('dupfield'), new SavedObjectNotFound('dashboard', '123')];

errors.forEach(error => {
const className = error.constructor.name;
@@ -70,7 +33,7 @@ describe('ui/errors', () => {
expect(error.stack).to.not.be.empty();
});

it (`${className} is an instance of KbnError`, () => {
it(`${className} is an instance of KbnError`, () => {
expect(error instanceof KbnError).to.be(true);
});
});
70 changes: 70 additions & 0 deletions src/plugins/kibana_utils/public/errors/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* eslint-disable max-classes-per-file */

// abstract error class
export class KbnError extends Error {
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}

/**
* when a mapping already exists for a field the user is attempting to add
* @param {String} name - the field name
*/
export class DuplicateField extends KbnError {
constructor(name: string) {
super(`The field "${name}" already exists in this mapping`);
}
}

/**
* A saved object was not found
*/
export class SavedObjectNotFound extends KbnError {
public savedObjectType: string;
public savedObjectId?: string;
constructor(type: string, id?: string, link?: string) {
const idMsg = id ? ` (id: ${id})` : '';
let message = `Could not locate that ${type}${idMsg}`;

if (link) {
message += `, [click here to re-create it](${link})`;
}

super(message);

this.savedObjectType = type;
this.savedObjectId = id;
}
}

/**
* This error is for scenarios where a saved object is detected that has invalid JSON properties.
* There was a scenario where we were importing objects with double-encoded JSON, and the system
* was silently failing. This error is now thrown in those scenarios.
*/
export class InvalidJSONProperty extends KbnError {
constructor(message: string) {
super(message);
}
}
20 changes: 20 additions & 0 deletions src/plugins/kibana_utils/public/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './errors';
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/public/index.ts
Original file line number Diff line number Diff line change
@@ -19,3 +19,4 @@

export * from './store';
export * from './parse';
export * from './errors';
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/public/util/ml_error.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { KbnError } from 'ui/errors';
import { KbnError } from '../../../../../../src/plugins/kibana_utils/public';

export class MLRequestFailure extends KbnError {
// takes an Error object and and optional response object