How to use the request-promise-core/errors.StatusCodeError function in request-promise-core

To help you get started, we’ve selected a few request-promise-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-gitlab / node-gitlab / src / infrastructure / XMLHttpRequester.ts View on Github external
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;
}

request-promise-core

Core Promise support implementation for the simplified HTTP request client 'request'.

ISC
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis