diff --git a/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts b/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts index 254bc0ae21f6c..a38e0d58abf89 100644 --- a/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts +++ b/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import { SearchResponse } from 'elasticsearch'; +import type { estypes } from '@elastic/elasticsearch'; import { IScopedClusterClient, IUiSettingsClient } from 'src/core/server'; import { IScopedSearchClient } from 'src/plugins/data/server'; import { Datatable } from 'src/plugins/expressions/server'; @@ -93,7 +93,7 @@ export class CsvGenerator { }; const results = ( await this.clients.data.search(searchParams, { strategy: ES_SEARCH_STRATEGY }).toPromise() - ).rawResponse as SearchResponse; + ).rawResponse as estypes.SearchResponse; return results; } @@ -107,7 +107,7 @@ export class CsvGenerator { scroll_id: scrollId, }, }) - ).body as SearchResponse; + ).body; return results; } @@ -321,13 +321,13 @@ export class CsvGenerator { if (this.cancellationToken.isCancelled()) { break; } - let results: SearchResponse | undefined; + let results: estypes.SearchResponse | undefined; if (scrollId == null) { // open a scroll cursor in Elasticsearch results = await this.scan(index, searchSource, scrollSettings); scrollId = results?._scroll_id; if (results.hits?.total != null) { - totalRecords = results.hits.total; + totalRecords = results.hits.total as number; this.logger.debug(`Total search results: ${totalRecords}`); } } else { diff --git a/x-pack/plugins/reporting/server/routes/generation.ts b/x-pack/plugins/reporting/server/routes/generation.ts index e90e059c11c67..0047afa4d9d7b 100644 --- a/x-pack/plugins/reporting/server/routes/generation.ts +++ b/x-pack/plugins/reporting/server/routes/generation.ts @@ -6,7 +6,6 @@ */ import Boom from '@hapi/boom'; -import { errors as elasticsearchErrors } from 'elasticsearch'; import { kibanaResponseFactory } from 'src/core/server'; import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; @@ -17,8 +16,6 @@ import { registerLegacy } from './legacy'; import { registerGenerateCsvFromSavedObjectImmediate } from './csv_searchsource_immediate'; import { HandlerFunction } from './types'; -const esErrors = elasticsearchErrors as Record; - const getDownloadBaseUrl = (reporting: ReportingCore) => { const config = reporting.getConfig(); return config.kbnConfig.get('server', 'basePath') + `${API_BASE_URL}/jobs/download`; @@ -78,24 +75,6 @@ export function registerJobGenerationRoutes(reporting: ReportingCore, logger: Lo }); } - if (err instanceof esErrors['401']) { - return res.unauthorized({ - body: `Sorry, you aren't authenticated`, - }); - } - - if (err instanceof esErrors['403']) { - return res.forbidden({ - body: `Sorry, you are not authorized`, - }); - } - - if (err instanceof esErrors['404']) { - return res.notFound({ - body: err.message, - }); - } - // unknown error, can't convert to 4xx throw err; }