Skip to content

Commit

Permalink
Moved KbnError base class ⇒ kibana_utils (elastic#45532) (elastic#45809)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Liza Katz authored Sep 17, 2019
1 parent d79449e commit 273bba5
Show file tree
Hide file tree
Showing 36 changed files with 245 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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


function isScriptedRange(filter) {
Expand Down
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
Expand Up @@ -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`);
}
}

Expand All @@ -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
);
}
}
Expand All @@ -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');
}
}

Expand All @@ -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
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
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
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ''
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ''
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -36,6 +37,7 @@ jest.mock('ui/errors', () => ({
}
},
}));
import { SavedObjectNotFound } from '../../../../../../../../../plugins/kibana_utils/public';

describe('resolveSavedObjects', () => {
describe('resolveSavedObjects', () => {
Expand Down Expand Up @@ -81,7 +83,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
Expand All @@ -95,7 +96,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
Expand All @@ -109,7 +109,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
Expand Down Expand Up @@ -175,7 +174,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'search',
});
Expand All @@ -189,7 +187,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
Expand All @@ -204,7 +201,6 @@ describe('resolveSavedObjects', () => {
savedSearchId: '1',
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
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
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
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;
}
}
Loading

0 comments on commit 273bba5

Please sign in to comment.