@algolia/requester-fetch
Advanced tools
Comparing version 5.10.0 to 5.10.1
@@ -1,61 +0,8 @@ | ||
// src/createFetchRequester.ts | ||
function isAbortError(error) { | ||
return error instanceof Error && error.name === "AbortError"; | ||
} | ||
function getErrorMessage(error, abortContent) { | ||
if (isAbortError(error)) { | ||
return abortContent; | ||
} | ||
return error instanceof Error ? error.message : "Network request failed"; | ||
} | ||
function createFetchRequester({ requesterOptions = {} } = {}) { | ||
async function send(request) { | ||
const abortController = new AbortController(); | ||
const signal = abortController.signal; | ||
const createTimeout = (timeout) => { | ||
return setTimeout(() => { | ||
abortController.abort(); | ||
}, timeout); | ||
}; | ||
const connectTimeout = createTimeout(request.connectTimeout); | ||
let fetchRes; | ||
try { | ||
fetchRes = await fetch(request.url, { | ||
method: request.method, | ||
body: request.data || null, | ||
redirect: "manual", | ||
signal, | ||
...requesterOptions, | ||
headers: { | ||
...requesterOptions.headers, | ||
...request.headers | ||
} | ||
}); | ||
} catch (error) { | ||
return { | ||
status: 0, | ||
content: getErrorMessage(error, "Connection timeout"), | ||
isTimedOut: isAbortError(error) | ||
}; | ||
} | ||
clearTimeout(connectTimeout); | ||
createTimeout(request.responseTimeout); | ||
try { | ||
const content = await fetchRes.text(); | ||
return { | ||
content, | ||
isTimedOut: false, | ||
status: fetchRes.status | ||
}; | ||
} catch (error) { | ||
return { | ||
status: 0, | ||
content: getErrorMessage(error, "Socket timeout"), | ||
isTimedOut: isAbortError(error) | ||
}; | ||
} | ||
} | ||
return { send }; | ||
} | ||
import { Requester } from '@algolia/client-common'; | ||
export { createFetchRequester }; | ||
type FetchRequesterOptions = { | ||
readonly requesterOptions?: RequestInit; | ||
}; | ||
declare function createFetchRequester({ requesterOptions }?: FetchRequesterOptions): Requester; | ||
export { type FetchRequesterOptions, createFetchRequester }; |
@@ -1,61 +0,8 @@ | ||
// src/createFetchRequester.ts | ||
function isAbortError(error) { | ||
return error instanceof Error && error.name === "AbortError"; | ||
} | ||
function getErrorMessage(error, abortContent) { | ||
if (isAbortError(error)) { | ||
return abortContent; | ||
} | ||
return error instanceof Error ? error.message : "Network request failed"; | ||
} | ||
function createFetchRequester({ requesterOptions = {} } = {}) { | ||
async function send(request) { | ||
const abortController = new AbortController(); | ||
const signal = abortController.signal; | ||
const createTimeout = (timeout) => { | ||
return setTimeout(() => { | ||
abortController.abort(); | ||
}, timeout); | ||
}; | ||
const connectTimeout = createTimeout(request.connectTimeout); | ||
let fetchRes; | ||
try { | ||
fetchRes = await fetch(request.url, { | ||
method: request.method, | ||
body: request.data || null, | ||
redirect: "manual", | ||
signal, | ||
...requesterOptions, | ||
headers: { | ||
...requesterOptions.headers, | ||
...request.headers | ||
} | ||
}); | ||
} catch (error) { | ||
return { | ||
status: 0, | ||
content: getErrorMessage(error, "Connection timeout"), | ||
isTimedOut: isAbortError(error) | ||
}; | ||
} | ||
clearTimeout(connectTimeout); | ||
createTimeout(request.responseTimeout); | ||
try { | ||
const content = await fetchRes.text(); | ||
return { | ||
content, | ||
isTimedOut: false, | ||
status: fetchRes.status | ||
}; | ||
} catch (error) { | ||
return { | ||
status: 0, | ||
content: getErrorMessage(error, "Socket timeout"), | ||
isTimedOut: isAbortError(error) | ||
}; | ||
} | ||
} | ||
return { send }; | ||
} | ||
import { Requester } from '@algolia/client-common'; | ||
export { createFetchRequester }; | ||
type FetchRequesterOptions = { | ||
readonly requesterOptions?: RequestInit; | ||
}; | ||
declare function createFetchRequester({ requesterOptions }?: FetchRequesterOptions): Requester; | ||
export { type FetchRequesterOptions, createFetchRequester }; |
{ | ||
"name": "@algolia/requester-fetch", | ||
"version": "5.10.0", | ||
"version": "5.10.1", | ||
"description": "Promise-based request library using Fetch.", | ||
@@ -50,3 +50,3 @@ "repository": { | ||
"dependencies": { | ||
"@algolia/client-common": "5.10.0" | ||
"@algolia/client-common": "5.10.1" | ||
}, | ||
@@ -53,0 +53,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
17776
166
+ Added@algolia/client-common@5.10.1(transitive)
- Removed@algolia/client-common@5.10.0(transitive)