You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Support client retries
* typo
* Update README.md with Rodric's suggestion
Co-authored-by: rodric rabbah <[email protected]>
* add no retry test + fix test nock race conditions
* retry spy + test no retry on success
* trigger travis build
* install only production dependencies for nnewer npm versionns
* back to old npm prod install + increase size too 2k
* actually let s try to update the npm prod install
Co-authored-by: rodric rabbah <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -105,7 +105,7 @@ _Client constructor supports the following mandatory parameters:_
105
105
-**key**. Client key to use when connecting to the `apihost` (if `nginx_ssl_verify_client` is turned on in your apihost)
106
106
-**proxy.** HTTP(s) URI for proxy service to forwards requests through. Uses Needle's [built-in proxy support](https://github.com/tomas/needle#request-options).
107
107
-**agent.** Provide custom [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) implementation.
108
-
108
+
-**retry**. Provide a retry options to retry on errors, for example, `{ retries: 2 }`. By default, no retries will be done. Uses [async-retry options](https://github.com/vercel/async-retry#api). Default values are different from async-retry, please refer to the API doc.
* This implements a request-promise-like facade over the needle
@@ -77,6 +78,13 @@ const rp = opts => {
77
78
})
78
79
}
79
80
81
+
constrpWithRetry=opts=>{
82
+
returnretry(bail=>{
83
+
// will retry on exception
84
+
returnrp(opts)
85
+
},opts.retry)
86
+
}
87
+
80
88
classClient{
81
89
/**
82
90
* @constructor
@@ -93,6 +101,13 @@ class Client {
93
101
* @param {boolean} [options.noUserAgent]
94
102
* @param {string} [options.cert]
95
103
* @param {string} [options.key]
104
+
* @param {object} [options.retry]
105
+
* @param {number} [options.retry.retries] Number of retries on top of the initial request, default is 2.
106
+
* @param {number} [options.retry.factor] Exponential factor, default is 2.
107
+
* @param {number} [options.retry.minTimeout] Milliseconds before the first retry, default is 100.
108
+
* @param {number} [options.retry.maxTimeout] Max milliseconds in between two retries, default is infinity.
109
+
* @param {boolean} [options.retry.randomize] Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is true.
110
+
* @param {Function} [options.retry.onRetry] An optional function that is invoked after a new retry is performed. It's passed the Error that triggered it as a parameter.
96
111
*/
97
112
constructor(options){
98
113
this.options=this.parseOptions(options||{})
@@ -135,7 +150,21 @@ class Client {
135
150
thrownewError(`${messages.INVALID_OPTIONS_ERROR} Missing either api or apihost parameters.`)
0 commit comments