adobe / adobe/target-nodejs-sdk

Retry logic is masking actual exception details when it encounters Timeout Exception.

Open
#55 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
26
Forks
22
PR merge metrics
No merged PRs in 30d

Description

I am setting timeout to 500ms for target SDK requests but unable to get exception details when there are bad request or other exceptions that SDK is throwing. SDK is internally adding retry logic while making AT delivery API calls, if the configured timeout period is less than the time takes to complete retries (10=maximum number of retries) then the actual exception details are masked with Timeout exception.

**Is there anyway we can override retry mechanism?**

### Reproduce Scenario (including but not limited to)
Set Timeout to lower number and make Target request with invalid values. The SDK returns Timeout exception and does not provides Bad request details.

#### Platform and Version
**2.1.6**

//networking.js
```
export function getFetchWithRetry( fetchApi, maxRetries = DEFAULT_NUM_FETCH_RETRIES, errorFunc = errorMessage => errorMessage, incidentalFailureCallback = noop) { return function fetchWithRetry(url, options, numRetries = maxRetries) { return fetchApi(url, options) .then(res => { if (!res.ok && res.status !== NOT_MODIFIED) { throw Error(res.statusText); } return res; }) .catch(err => { if (isFunction(incidentalFailureCallback)) { incidentalFailureCallback.call(undefined, err); }
if (numRetries < 1) { throw new Error(errorFunc(err.message)); } // TODO: Enhance this to do Exponential Backoff return fetchWithRetry(url, options, numRetries - 1); }); };}

//delivery-api-client/index.js
get fetchApi() {
const timeout = this.configuration.timeout;
const fetch = this.configuration.fetchApi || window.fetch.bind(window);
return function (input, init) {
return new Promise((resolve, reject) => {
**let timer = setTimeout(() => reject(new Error('Request timed out')), timeout);**
fetch(input, init).then(response => resolve(response), err => reject(err)).finally(() => clearTimeout(timer));
});
};
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.