$ npm install @adobe/aio-lib-core-networking
- Initialize the SDK
const fetchRetry = require('@adobe/aio-lib-core-networking')
- Call methods using the initialized SDK
const fetchRetry = require('@adobe/aio-lib-core-networking')
async function sdkTest() {
return new Promise((resolve, reject) => {
fetchRetry.exponentialBackoff(url, requestOptions, retryOptions, retryOn, retryDelay)
.then((response) => {
if (!response.ok) {
throw Error(reduceError(response))
}
resolve(response.json())
})
.catch(err => {
reject(
new codes.ERROR_GET_SOMETHING({ sdkDetails, messageValues: err }))
})
})
}
This class provides methods to implement fetch with retries. The retries use exponential backoff strategy with defaults set to max of 3 retries and initial Delay as 100ms
Kind: inner class of @adobe/aio-lib-core-networking
httpExponentialBackoff.exponentialBackoff(url, requestOptions, retryOptions, retryOn, retryDelay) ⇒ Promise.<Response>
This function will retry connecting to a url end-point, with exponential backoff. Returns a Promise.
Kind: instance method of HttpExponentialBackoff
Returns: Promise.<Response>
- Promise object representing the http response
Param | Type | Description |
---|---|---|
url | string |
endpoint url |
requestOptions | object |
request options which includes the HTTP method, headers, timeout, etc. |
retryOptions | object |
retry options with options being maxRetries and initialDelayInMillis |
retryOn | function | Array |
Optional Function or Array. If provided, will be used instead of the default |
retryDelay | function | number |
Optional Function or number. If provided, will be used instead of the default |
LOG_LEVEL=debug <your_call_here>
Prepend the LOG_LEVEL
environment variable and debug
value to the call that invokes your function, on the command line. This should output a lot of debug data for your SDK calls.
Contributions are welcome! Read the Contributing Guide for more information.
This project is licensed under the Apache V2 License. See LICENSE for more information.