Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 3 Examples of "request-promise-core in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'request-promise-core' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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;
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
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;
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now