NodeJS API Call Frequent timeout

I'm using the Shopify SDK 'Shopiy-API-Node' and get frequent timeout while requesting datas from the REST Api.

I've got two files, one file that check if everything is ok to execute the query (getProducts.js), the other that make the API call (call.js)

Here is the code I'm using :

getProducts.js :

var db = require('../util/checkIds.js');
var shopify = require('./call.js');


module.exports = {
  getProducts: function(postApiKey, postApiPass, postApiSite, callback) {
    if (postApiKey && postApiPass && postApiSite) {
      //Check in database if the value exist
      db.checkIds(postApiKey, postApiPass, postApiSite, function(error, data) {
        if (error) {
          //If an issue occured while querrying the DB let's display it
          callback(error, null); //Display the error while querrying the database
        } else {
          if (data.length > 0) {
            //If the value exist, let's get the products of the user
            const datas = shopify.fetchProducts();
            datas.then(function(result) {
              callback(null, result);
            })
          } else {
            //If the ids don't exist, let's display it too
            callback('Error : The provided credentials mismatch', null);
          }
        }
      });
    } else {
      callback('Error : No credentials have been defined', null);
    }
  }
};

call.js

var shopify = require('../util/shopifyConnect.js');

fetchProducts: async function() {
    try {
      //THIS AWAIT NEVER ENDS AND TIMEOUT
      const products = await shopify().product.list({ limit: 250});
      return products;
    } catch (err) {
      // handle err
      return err;
    }
  }

"shopify()" only returns a new instance to connect to the API, I'm sure it works.

So far, I'm afraid this is related with API quota, but to be sure could you please help and provide me best practices to avoid this kind of issue.

Thanks.



Read more here: https://stackoverflow.com/questions/64894854/nodejs-api-call-frequent-timeout

Content Attribution

This content was originally published by f1rstsurf at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: