request-repeat
Wraps both request-promise-native and retry-as-promised together, in order to provide an easy way to do requests with retries while returning a promise.
Note: request-promise option resolveWithFullResponse
will be always set to true
. Hence, the result of any successful request would always contain the full response, regardless its user-defined value.
API
request-repeat should support all request-promise-native functionality, so you can pass all options as you would pass them to the original package
retry
request-repeat should support all retry-as-promised functionality, so you can pass all options as you would pass them to the original package by setting them in retry object
retry: /* retry-as-promised options */
In addition to the original package options, the following extra options are accepted
retryOn5xx
enable retry on any 5xx error
retry: retryOn5xx: true
retryStrategyFn
a function that is used to decide on what other cases to do a retry
retry: { // return a boolean }
successFn
a function that is called on success
retry: { // do something on success }
errorFn
a function that is called on error
retry: { // do something on error }
Usage
var request = ; var options = url: 'http://www.site-with-issues.com' body: /* body */ json: true retry: max: 3 backoffBase: 500 retryOn5xx: true { return responsestatusCode === 500 && responsebody; } { console; } { console; }
Result
> request...- "Request to http://www.site-with-issues.com failed on the 1 attempt with RequestError: Error: getaddrinfo ENOTFOUND www.site-with-issues.com www.site-with-issues.com:80"- "Request to http://www.site-with-issues.com failed on the 2 attempt with RequestError: Error: getaddrinfo ENOTFOUND www.site-with-issues.com www.site-with-issues.com:80"- "Got status-code 200 on request to http://www.site-with-issues.com"
Usage with defaults
var request = ; var requestWithDefaults = request; requestWithDefaultsthen...