Skip to content

Commit

Permalink
[Maps] [File upload] Fix maps geojson upload hanging on index step (#…
Browse files Browse the repository at this point in the history
…42623) (#42983)

* 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
  • Loading branch information
Aaron Caldwell authored Aug 9, 2019
1 parent 5dc36cb commit 4a0c8c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
44 changes: 11 additions & 33 deletions x-pack/legacy/plugins/file_upload/public/util/http_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 }
}));
});
})]
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4a0c8c9

Please sign in to comment.