Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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");
    }
  });
});
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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. –  vlio20 Jun 2 '13 at 15:45
    
there were some mistakes (logic and syntax), so after correcting them and doing as @Hector Ramos suggested ALL WORKS FINE! thanks!!! –  vlio20 Jun 2 '13 at 18:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.