From 7b773733b74501627dace6116415c0414c36cd09 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 9 Aug 2019 12:28:16 -0600 Subject: [PATCH] [7.3] [Maps] [File upload] Fix maps geojson upload hanging on index step (#42623) (#43033) * [Maps] [File upload] Fix maps geojson upload hanging on index step (#42623) * Remove timeout from fetch. Falls back to 30 second timeout on server-side indexing call * Handle when indexing request is a success but every doc failed * Return failures array from catch * Review feedback * Review feedback # Conflicts: # x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/geojson_file_source.js * Indentation --- .../file_upload/public/util/http_service.js | 44 +++++-------------- .../client_file_source/geojson_file_source.js | 8 +++- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/x-pack/legacy/plugins/file_upload/public/util/http_service.js b/x-pack/legacy/plugins/file_upload/public/util/http_service.js index 44a6a0b31c7a..26d46cecb0e5 100644 --- a/x-pack/legacy/plugins/file_upload/public/util/http_service.js +++ b/x-pack/legacy/plugins/file_upload/public/util/http_service.js @@ -4,16 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ - - // service for interacting with the server import chrome from 'ui/chrome'; import { addSystemApiHeader } from 'ui/system_api'; import { i18n } from '@kbn/i18n'; -const FETCH_TIMEOUT = 10000; - export async function http(options) { if(!(options && options.url)) { throw( @@ -40,38 +36,20 @@ export async function http(options) { if (body !== null) { payload.body = body; } - return await fetchWithTimeout(url, payload); + return await doFetch(url, payload); } -async function fetchWithTimeout(url, payload) { - let timedOut = false; - - return new Promise(function (resolve, reject) { - const timeout = setTimeout(function () { - timedOut = true; - reject(new Error( - i18n.translate('xpack.fileUpload.httpService.requestTimedOut', - { defaultMessage: 'Request timed out' })) - ); - }, FETCH_TIMEOUT); - - fetch(url, payload) - .then(resp => { - clearTimeout(timeout); - if (!timedOut) { - resolve(resp); - } - }) - .catch(function (err) { - reject(err); - if (timedOut) return; - }); - }).then(resp => resp.json()) - .catch(function (err) { - console.error( +async function doFetch(url, payload) { + try { + const resp = await fetch(url, payload); + return resp.json(); + } catch(err) { + return { + failures: [ i18n.translate('xpack.fileUpload.httpService.fetchError', { defaultMessage: 'Error performing fetch: {error}', values: { error: err.message } - })); - }); + })] + }; + } } diff --git a/x-pack/legacy/plugins/maps/public/shared/layers/sources/client_file_source/geojson_file_source.js b/x-pack/legacy/plugins/maps/public/shared/layers/sources/client_file_source/geojson_file_source.js index 91c87d4af048..9ebdc4e8e00b 100644 --- a/x-pack/legacy/plugins/maps/public/shared/layers/sources/client_file_source/geojson_file_source.js +++ b/x-pack/legacy/plugins/maps/public/shared/layers/sources/client_file_source/geojson_file_source.js @@ -52,8 +52,12 @@ export class GeojsonFileSource extends AbstractVectorSource { ) => { return (indexResponses = {}) => { const { indexDataResp, indexPatternResp } = indexResponses; - if (!(indexDataResp && indexDataResp.success) || - !(indexPatternResp && indexPatternResp.success)) { + + const indexCreationFailed = !(indexDataResp && indexDataResp.success); + const allDocsFailed = indexDataResp.failures.length === indexDataResp.docCount; + const indexPatternCreationFailed = !(indexPatternResp && indexPatternResp.success); + + if (indexCreationFailed || allDocsFailed || indexPatternCreationFailed) { importErrorHandler(indexResponses); return; }