diff --git a/src/main/ts/common/HttpClient.ts b/src/main/ts/common/HttpClient.ts index 9aaf1fa0d..a610e4179 100644 --- a/src/main/ts/common/HttpClient.ts +++ b/src/main/ts/common/HttpClient.ts @@ -92,13 +92,16 @@ export default class HttpClient { // request using fetch or xhr with timeout let timeout = request.timeout === undefined ? HttpClient.DEFAULT_TIMEOUT : request.timeout === 0 ? HttpClient.MAX_TIMEOUT : request.timeout; let requestPromise = request.requestApi === "fetch" ? HttpClient.requestFetch(request) : HttpClient.requestXhr(request); + let timeoutId; let timeoutPromise = new Promise((resolve, reject) => { - let id = setTimeout(() => { - clearTimeout(id); + timeoutId = setTimeout(() => { + clearTimeout(timeoutId); reject('Request timed out in '+ timeout + ' milliseconds') }, timeout); }); - return Promise.race([requestPromise, timeoutPromise]); + let response = await Promise.race([requestPromise, timeoutPromise]); + clearTimeout(timeoutId); + return response; } // ----------------------------- PRIVATE HELPERS ----------------------------