robust-http-fetch
Advanced tools
Comparing version 1.1.13 to 1.1.14
25
index.js
@@ -18,5 +18,5 @@ /** | ||
checkArgs(...arguments); | ||
const {timeout, maxRequests} = init; | ||
const logger = getLogger(optLogger); | ||
const {timeout, maxRequests} = init; | ||
const fetcher = oneoffFetch(url, init); | ||
const worker = requestWorker(url, init); | ||
@@ -26,17 +26,14 @@ // container holding scheduled timer, entry is a 2-values array, 1st is SN(SeqNumber) of scheduled request, 2nd is timer ID; | ||
const oneoffFetchWrapper = () => { | ||
const doFetch = (cb, sn, startTime) => { | ||
logger(`#${sn} request about to fire`); | ||
let result; | ||
try { | ||
const promise = fetcher(); | ||
return Promise.resolve(promise); | ||
const promise = worker(); | ||
result = Promise.resolve(promise); | ||
} catch (e) { | ||
return Promise.reject(e.message); | ||
result = Promise.reject(e.message); | ||
} | ||
cb(result, sn, startTime); | ||
}; | ||
const doFetch = (cb, sn, startTime) => { | ||
logger(`#${sn} request about to fire`); | ||
const promise = oneoffFetchWrapper(); | ||
cb(promise, sn, startTime); | ||
}; | ||
const invokeCallback = (promise, sn, startTime) => { | ||
@@ -102,3 +99,3 @@ callback(promise | ||
function oneoffFetch(url, init) { | ||
function requestWorker(url, init) { | ||
const {mockTestOnlyFetch} = init; | ||
@@ -167,3 +164,3 @@ if (mockTestOnlyFetch) { | ||
robustHttpFetchAsPromise.oneoffFetch = oneoffFetch; | ||
robustHttpFetchAsPromise.oneoffFetch = requestWorker; | ||
robustHttpFetchAsPromise.robustHttpFetch = robustHttpFetch; | ||
@@ -170,0 +167,0 @@ |
{ | ||
"name": "robust-http-fetch", | ||
"description": "Redo the http request when timeout or failed, aim at providing resilience over plain one-off fetch request by doing retry delayed/failed requests", | ||
"version": "1.1.13", | ||
"version": "1.1.14", | ||
"repository": { | ||
@@ -53,4 +53,4 @@ "type": "git", | ||
"publishConfig": { | ||
"registry": "http://registry.npmjs.org/" | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} |
14681
144