Skip to content

Commit

Permalink
Simplify is_es_error_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Dec 9, 2019
1 parent f65a526 commit 3d0e61b
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { isEsErrorFactory } from './is_es_error_factory';
export { isEsError } from './is_es_error';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as legacyElasticsearch from 'elasticsearch';

const esErrorsParent = legacyElasticsearch.errors._Abstract;

export function isEsError(err: Error) {
return err instanceof esErrorsParent;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { RequestHandler } from 'src/core/server';
import { reduce, size } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';

Expand Down Expand Up @@ -61,7 +61,6 @@ function getIndices(callWithRequest: any, pattern: string, limit = 10) {
}

export function registerGetRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const { pattern } = request.body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { RequestHandler } from 'src/core/server';
import { callWithRequestFactory } from '../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../lib/is_es_error_factory';
import { isEsError } from '../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory';
// @ts-ignore
import { Fields } from '../../models/fields';
Expand All @@ -25,8 +25,6 @@ function fetchFields(callWithRequest: any, indexes: string[]) {
}

export function registerListFieldsRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);

const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const { indexes } = request.body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
import { get } from 'lodash';
import { RequestHandler } from 'src/core/server';
import { callWithRequestFactory } from '../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../lib/is_es_error_factory';
import { isEsError } from '../../lib/is_es_error';
import { INDEX_NAMES } from '../../../../common/constants';
import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../types';
Expand All @@ -29,7 +29,6 @@ function fetchHistoryItem(callWithRequest: any, watchHistoryItemId: string) {
}

export function registerLoadHistoryRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const id = request.params.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { IClusterClient, RequestHandler } from 'src/core/server';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
// @ts-ignore
import { Settings } from '../../../models/settings';
Expand All @@ -19,7 +19,6 @@ function fetchClusterSettings(client: IClusterClient) {
}

export function registerLoadRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
try {
const settings = await fetchClusterSettings(deps.elasticsearch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
import { get } from 'lodash';
import { RequestHandler } from 'src/core/server';
import { callWithRequestFactory } from '../../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../../lib/is_es_error_factory';
import { isEsError } from '../../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../../lib/license_pre_routing_factory';
// @ts-ignore
import { WatchStatus } from '../../../../models/watch_status';
Expand All @@ -22,7 +22,6 @@ function acknowledgeAction(callWithRequest: any, watchId: string, actionId: stri
}

export function registerAcknowledgeRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const { watchId, actionId } = request.params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
import { RequestHandler } from 'src/core/server';
import { get } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';
// @ts-ignore
Expand All @@ -21,7 +21,6 @@ function activateWatch(callWithRequest: any, watchId: string) {
}

export function registerActivateRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema';
import { RequestHandler } from 'src/core/server';
import { get } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';
// @ts-ignore
Expand All @@ -20,7 +20,6 @@ function deactivateWatch(callWithRequest: any, watchId: string) {
}

export function registerDeactivateRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { RequestHandler } from 'src/core/server';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';

Expand All @@ -18,7 +18,6 @@ function deleteWatch(callWithRequest: any, watchId: string) {
}

export function registerDeleteRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
import { RequestHandler } from 'src/core/server';
import { get } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';

import { RouteDependencies, ServerShim } from '../../../types';
Expand All @@ -29,7 +29,6 @@ function executeWatch(callWithRequest: any, executeDetails: any, watchJson: any)
}

export function registerExecuteRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const executeDetails = ExecuteDetails.fromDownstreamJson(request.body.executeDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { get } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { fetchAllFromScroll } from '../../../lib/fetch_all_from_scroll';
import { INDEX_NAMES, ES_SCROLL_SETTINGS } from '../../../../../common/constants';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';
// @ts-ignore
Expand Down Expand Up @@ -43,7 +43,6 @@ function fetchHistoryItems(callWithRequest: any, watchId: any, startTime: any) {
}

export function registerHistoryRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const { watchId } = request.params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
import { RequestHandler } from 'src/core/server';
import { get } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
// @ts-ignore
import { Watch } from '../../../models/watch';
Expand All @@ -21,7 +21,6 @@ function fetchWatch(callWithRequest: any, watchId: string) {
}

export function registerLoadRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
serializeThresholdWatch,
} from '../../../../../common/lib/serialization';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';

Expand All @@ -31,7 +31,6 @@ function saveWatch(callWithRequest: any, id: string, body: any) {
}

export function registerSaveRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const { id } = request.params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { RequestHandler } from 'src/core/server';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';

Expand All @@ -29,7 +29,6 @@ function fetchVisualizeData(callWithRequest: any, index: any, body: any) {
}

export function registerVisualizeRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);
const watch = Watch.fromDownstreamJson(request.body.watch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { get } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { fetchAllFromScroll } from '../../../lib/fetch_all_from_scroll';
import { INDEX_NAMES, ES_SCROLL_SETTINGS } from '../../../../../common/constants';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { isEsError } from '../../../lib/is_es_error';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { RouteDependencies, ServerShim } from '../../../types';
// @ts-ignore
Expand All @@ -31,7 +31,6 @@ function fetchWatches(callWithRequest: any) {
}

export function registerListRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(deps.elasticsearchService, request);

Expand Down

0 comments on commit 3d0e61b

Please sign in to comment.