How to use the requestretry function in requestretry

To help you get started, we’ve selected a few requestretry 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 vtex / toolbelt / src / lib / watch.js View on Github external
getSandboxFiles = () => {
    let options = {
      url: `${this.appsEndpoint}/${this.vendor}/sandboxes/${this.sandbox}/${this.app}/${this.version}/files?list=true&_limit=1000`,
      method: 'GET',
      headers: {
        Authorization: `token ${this.credentials.token}`,
        Accept: this.acceptHeader,
        'Content-Type': 'application/json',
        'x-vtex-accept-snapshot': false
      }
    };

    return request(options).then((response) => {
      if (response.statusCode === 200) {
        return JSON.parse(response.body).data.reduce((acc, file) => {
          acc[file.path] = { hash: file.hash };
          return acc;
        }, {});
      } else if (response.statusCode === 404) {
        return void 0;
      }

      return console.error('Status:', response.statusCode);
    });
  }
github tharyckgusmao / integrada.minhabiblioteca.com.br / app / components / ebook / EbookItemComponent.js View on Github external
}, (error, response, body) => {



            let $ = cheerio.load(body);
            let itemLink = $("#pbk-page").attr("src");
            let index = item.label;

            request({
              uri: URL_HOST + itemLink,
              jar: jar,
              maxAttempts: 5,
              retryDelay: 5000,
              retryStrategy: request.RetryStrategies.HTTPOrNetworkError
            }, (error, response, body) => {

              this.setState((prevState, props) => {
                return {
                  percent: prevState.percent + 1
                };
              },()=>{
                cb()
              });
github Festify / app / functions / lib / spotify-auth.ts View on Github external
function spotifyRequest(
    params: string | { [key: string]: any },
    url: string = API_URL,
    method: string = 'POST',
) {
    return request({
        agent,
        method,
        uri: url,
        form: params,
        headers: {
            'Authorization': `Basic ${authKey}`,
        },
        json: true,
        fullResponse: false,
    });
}
github vtex / toolbelt / src / lib / auth / login.js View on Github external
function getTemporaryToken() {
  let deferred = Q.defer();
  let requestOptions = {
    uri: 'https://vtexid.vtex.com.br/api/vtexid/pub/authentication/start?callbackUrl='
  };

  request(requestOptions, (error, response, body) => {
    if (error || response.statusCode !== 200 || response.statusCode >= 400) {
      return deferred.reject(getErrorMessage(error, response, 'authenticating'));
    }

    try {
      let token = JSON.parse(body).authenticationToken;
      deferred.resolve(token);
    } catch (err) {
      return deferred.reject('Invalid JSON while getting token from VTEX ID');
    }
  });

  return deferred.promise;
}
github vtex / toolbelt / src / lib / auth / login.js View on Github external
export function createWorkspace(credentials) {
  let deferred = Q.defer();
  let options = {
    url: `http://workspaces.vtex.com/${credentials.account}/workspaces`,
    method: 'POST',
    headers: {
      Authorization: `token ${credentials.token}`,
      Accept: 'application/vnd.vtex.gallery.v0+json',
      'Content-Type': 'application/json'
    },
    json: {
      name: 'sb_' + credentials.email
    }
  };

  request(options, (error, response) => {
    if (error || !(response.statusCode === 201 || response.statusCode === 409)) {
      return deferred.reject(getErrorMessage(error, response, 'creating workspace'));
    }

    return deferred.resolve(credentials);
  });

  return deferred.promise;
}
github vtex / toolbelt / src / lib / auth / credentials.js View on Github external
export function isTokenValid(credentials) {
  let deferred = Q.defer();
  let requestOptions = {
    uri: 'https://vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=' + (encodeURIComponent(credentials.token))
  };

  request(requestOptions, (error, response, body) => {
    if (error || response.statusCode !== 200 || response.statusCode >= 400) {
      return deferred.reject(getErrorMessage(error, response, 'authenticating'));
    }

    try {
      let vtexIdUser = JSON.parse(body);
      if (vtexIdUser === null) {
        return deferred.resolve(false);
      }
      let user = vtexIdUser.user;
      if (user !== null && user === credentials.email) {
        return deferred.resolve(true);
      }
    } catch (err) {
      return deferred.reject('Invalid JSON while getting token from VTEX ID');
    }
github vtex / toolbelt / src / lib / watch.js View on Github external
Accept: this.acceptHeader,
        'Content-Type': 'application/json',
        'x-vtex-accept-snapshot': false
      }
    };

    if (refresh) options.url += '?resync=true';

    if (refresh) {
      spinner = ora(chalk.blue('Synchronizing...'));
    } else {
      spinner = ora(chalk.blue('Changes detected, uploading...'));
    }
    spinner.start();

    return request(options, (error, response) => {
      spinner.stop();

      if (error || response.statusCode !== 200 || response.statusCode >= 400) {
        return this.changeSendError(error, response);
      }

      return this.changesSentSuccessfuly(response.body);
    });
  }
github vtex / toolbelt / src / lib / auth / login.js View on Github external
function getEmailAuthenticationToken(email, token, code) {
  let deferred = Q.defer();
  let options = {
    url: 'https://vtexid.vtex.com.br/api/vtexid/pub/authentication/accesskey/' + ('validate?&login=' + email + '&accesskey=' + code) + ('&authenticationToken=' + token),
    method: 'GET'
  };

  request(options, (error, response, body) => {
    if (error || response.statusCode !== 200 || response.statusCode >= 400) {
      return deferred.reject(getErrorMessage(error, response, 'authenticating'));
    }

    try {
      let auth = JSON.parse(body);
      if (auth.authStatus !== 'Success') {
        deferred.reject(chalk.red('Authentication has failed with status ' + auth.authStatus));
      }
      return deferred.resolve(auth.authCookie.Value);
    } catch (_error) {
      return deferred.reject(chalk.red('Invalid JSON while authenticating with VTEX ID'));
    }
  });

  return deferred.promise;

requestretry

request-retry wrap nodejs request to retry http(s) requests in case of error

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Similar packages