Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] [File upload] Fix maps geojson upload hanging on index step #42623

Merged
merged 6 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 8 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,17 @@ 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) {
kindsun marked this conversation as resolved.
Show resolved Hide resolved
return fetch(url, payload)
kindsun marked this conversation as resolved.
Show resolved Hide resolved
.then(resp => resp.json())
.catch(err => ({
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 @@ -53,6 +53,7 @@ export class GeojsonFileSource extends AbstractVectorSource {
return (indexResponses = {}) => {
const { indexDataResp, indexPatternResp } = indexResponses;
if (!(indexDataResp && indexDataResp.success) ||
kindsun marked this conversation as resolved.
Show resolved Hide resolved
indexDataResp.failures.length === indexDataResp.docCount ||
!(indexPatternResp && indexPatternResp.success)) {
importErrorHandler(indexResponses);
return;
Expand Down