Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async function getResponse(
opts: XhrUriConfig & XhrConfgExtraParams | XhrUrlConfig & XhrConfgExtraParams,
) {
const response = await promisifiedFn(opts);
const sleepTime = parseInt(response.headers['retry-after'], 10);
if (response.statusCode === 429 && sleepTime) {
await wait(sleepTime * 1000);
} else if (response.statusCode >= 400 && response.statusCode <= 599) {
throw new StatusCodeError(response.statusCode, response.body, {}, null);
}
return opts.resolveWithFullResponse ? response : response.body;
} as XhrInstancePromisified;
}