How to use request-promise-core - 3 common examples

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 codemanki / cloudscraper / errors.js View on Github external
1004: 'Host Not Configured to Serve Web Traffic',
  1005: 'Access Denied: IP of banned ASN/ISP',
  1010: 'The owner of this website has banned your access based on your browser\'s signature',
  1011: 'Access Denied (Hotlinking Denied)',
  1012: 'Access Denied',
  1013: 'HTTP hostname and TLS SNI hostname mismatch',
  1016: 'Origin DNS error',
  1018: 'Domain is misconfigured',
  1020: 'Access Denied (Custom Firewall Rules)'
};

ERROR_CODES[1006] =
    ERROR_CODES[1007] =
        ERROR_CODES[1008] = 'Access Denied: Your IP address has been banned';

const OriginalError = original.RequestError;

const RequestError = create('RequestError', 0);
const CaptchaError = create('CaptchaError', 1);

// errorType 4 is a CloudflareError so this constructor is reused.
const CloudflareError = create('CloudflareError', 2, function (error) {
  if (!isNaN(error.cause)) {
    const description = ERROR_CODES[error.cause] || http.STATUS_CODES[error.cause];
    if (description) {
      error.message = error.cause + ', ' + description;
    }
  }
});

const ParserError = create('ParserError', 3, function (error) {
  error.message = BUG_REPORT + error.message;
github codemanki / cloudscraper / errors.js View on Github external
if (!isNaN(error.cause)) {
    const description = ERROR_CODES[error.cause] || http.STATUS_CODES[error.cause];
    if (description) {
      error.message = error.cause + ', ' + description;
    }
  }
});

const ParserError = create('ParserError', 3, function (error) {
  error.message = BUG_REPORT + error.message;
});

// The following errors originate from promise-core and it's dependents.
// Give them an errorType for consistency.
original.StatusCodeError.prototype.errorType = 5;
original.TransformError.prototype.errorType = 6;

// This replaces the RequestError for all libraries using request/promise-core
// and prevents silent failure.
Object.defineProperty(original, 'RequestError', {
  configurable: true,
  enumerable: true,
  writable: true,
  value: RequestError
});

// Export our custom errors along with StatusCodeError, etc.
Object.assign(module.exports, original, {
  RequestError: RequestError,
  CaptchaError: CaptchaError,
  ParserError: ParserError,
  CloudflareError: CloudflareError
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