@algolia/requester-browser-xhr
Advanced tools
Comparing version 4.0.0-beta.4 to 4.0.0-beta.5
@@ -12,11 +12,28 @@ 'use strict'; | ||
Object.keys(request.headers).forEach(key => baseRequester.setRequestHeader(key, request.headers[key])); | ||
const timeoutHandler = setTimeout(() => { | ||
baseRequester.abort(); | ||
resolve({ status: 0, content: '', isTimedOut: true }); | ||
}, request.timeout * 1000); | ||
const createTimeout = (timeout, content) => { | ||
return setTimeout(() => { | ||
baseRequester.abort(); | ||
resolve({ | ||
status: 0, | ||
content, | ||
isTimedOut: true, | ||
}); | ||
}, timeout * 1000); | ||
}; | ||
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout'); | ||
// eslint-disable-next-line functional/no-let | ||
let socketTimeout; | ||
// eslint-disable-next-line functional/immutable-data | ||
baseRequester.onreadystatechange = () => { | ||
if (baseRequester.readyState > baseRequester.OPENED && socketTimeout === undefined) { | ||
clearTimeout(connectTimeout); | ||
socketTimeout = createTimeout(request.socketTimeout, 'Socket timeout'); | ||
} | ||
}; | ||
// eslint-disable-next-line functional/immutable-data | ||
baseRequester.onerror = () => { | ||
// istanbul ignore next | ||
if (baseRequester.status === 0) { | ||
clearTimeout(timeoutHandler); | ||
clearTimeout(connectTimeout); | ||
clearTimeout(socketTimeout); | ||
resolve({ | ||
@@ -31,3 +48,4 @@ content: baseRequester.responseText || 'Network request failed', | ||
baseRequester.onload = () => { | ||
clearTimeout(timeoutHandler); | ||
clearTimeout(connectTimeout); | ||
clearTimeout(socketTimeout); | ||
resolve({ | ||
@@ -34,0 +52,0 @@ content: baseRequester.responseText, |
@@ -8,11 +8,28 @@ function createBrowserXhrRequester() { | ||
Object.keys(request.headers).forEach(key => baseRequester.setRequestHeader(key, request.headers[key])); | ||
const timeoutHandler = setTimeout(() => { | ||
baseRequester.abort(); | ||
resolve({ status: 0, content: '', isTimedOut: true }); | ||
}, request.timeout * 1000); | ||
const createTimeout = (timeout, content) => { | ||
return setTimeout(() => { | ||
baseRequester.abort(); | ||
resolve({ | ||
status: 0, | ||
content, | ||
isTimedOut: true, | ||
}); | ||
}, timeout * 1000); | ||
}; | ||
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout'); | ||
// eslint-disable-next-line functional/no-let | ||
let socketTimeout; | ||
// eslint-disable-next-line functional/immutable-data | ||
baseRequester.onreadystatechange = () => { | ||
if (baseRequester.readyState > baseRequester.OPENED && socketTimeout === undefined) { | ||
clearTimeout(connectTimeout); | ||
socketTimeout = createTimeout(request.socketTimeout, 'Socket timeout'); | ||
} | ||
}; | ||
// eslint-disable-next-line functional/immutable-data | ||
baseRequester.onerror = () => { | ||
// istanbul ignore next | ||
if (baseRequester.status === 0) { | ||
clearTimeout(timeoutHandler); | ||
clearTimeout(connectTimeout); | ||
clearTimeout(socketTimeout); | ||
resolve({ | ||
@@ -27,3 +44,4 @@ content: baseRequester.responseText || 'Network request failed', | ||
baseRequester.onload = () => { | ||
clearTimeout(timeoutHandler); | ||
clearTimeout(connectTimeout); | ||
clearTimeout(socketTimeout); | ||
resolve({ | ||
@@ -30,0 +48,0 @@ content: baseRequester.responseText, |
{ | ||
"name": "@algolia/requester-browser-xhr", | ||
"version": "4.0.0-beta.4", | ||
"version": "4.0.0-beta.5", | ||
"private": false, | ||
@@ -11,2 +11,3 @@ "description": "Promise-based request library for browser using xhr.", | ||
], | ||
"sideEffects": false, | ||
"main": "index.js", | ||
@@ -16,4 +17,4 @@ "module": "dist/requester-browser-xhr.esm.js", | ||
"dependencies": { | ||
"@algolia/requester-common": "4.0.0-beta.4" | ||
"@algolia/requester-common": "4.0.0-beta.5" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6118
119
+ Added@algolia/requester-common@4.0.0-beta.5(transitive)
- Removed@algolia/requester-common@4.0.0-beta.4(transitive)