0

I am using parse.com as my backend. I have made the below cloud code, and it's giving me {u'code': 141, u'error': u'success/error was not called'} code. I know that I am not making the response.success call after the first success but I am doing it in the chained function called nextSaleRate. Is there any way to work it out?

Here is the full code:

function SaleWithRate(){
  saleId = undefined;
  rating = 0.0;
}

function nextSaleRate(saleList, nextSale, arr, response){
  if(nextSale < saleList.length) {
    var sale = new SaleWithRate();
    sale.saleId = saleList[nextSale].id;

    //creating ShaleSale object for Rates query
    var ShaleSale = Parse.Object.extend("ShaleSale");
    var saleForRate = new ShaleSale();
    saleForRate.id = sale.saleId;

    //query
    var rateQuery = new Parse.Query("ShaleSaleRate");
    rateQuery.equalTo("saleId", saleForRate);
    rateQuery.find({
      success: function(rateList) {
        var sum = 0;
        var index = 0;
        for(var j = 0; j < rateList.length; j++) {
          index++;
          sum += rateList[j].get("rate");
          if(index === 0) {
            sale.rating = 0;
          }
          else {
            sale.rating = sum/index;
          }
          arr.push(sale);
          nextSale++;
          nextSaleRate(saleList, nextSale, arr, response);
        }
      },
      error: function() {
        response.error("rate lookup failed");
      }
    });
  }
  else {
    console.log("when do I get in" + nextSale);
    response.success(arr);
  }
}

Parse.Cloud.define("getSalesWithRate", function(request, response){
  var query = new Parse.Query("ShaleSale");
  query.ascending("createdAt");
  //query.notContainedIn("objectId", request.params.saleIds);
  query.find({
    success: function(results) {
        var arr = new Array();
        nextSaleRate(results, 0, arr, response);
    },
    error: function() {
      response.error("sale lookup failed");
    }
  });
});

1 Answer 1

1

The error message is actually referring to the fact that response.success() is not being called from your Cloud Function. You're not passing the response object to your next Sale Rate function.

Sign up to request clarification or add additional context in comments.

2 Comments

I changed my code as you suggested @Hector Ramos but I am still getting the same error. I have edited the question, and now i am passing the response object to nextSaleRate.
there were some mistakes (logic and syntax), so after correcting them and doing as @Hector Ramos suggested ALL WORKS FINE! thanks!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.