Start a new topic

DataError: Data provided to an operation does not meet requirements

Hello


I'm currently testing my web app through all browsers on iOS and Android. There is one weird occasion that came up. The user can rate a product and therefore send his comment to the Kinvey cloud. This works all fine on :

iOS: Safari, Chrome, Firefox

Android: Chrome


On Firefox V68.0 (Chrome) I get this error message:


DataError: Data provided to an operation does not meet requirements.


The shortened code (saving user rating) looks like this:   

var productLogStore = Kinvey.DataStore.collection('productlogs');

var content = {
    '_id': logId,
     'userid': activeUser._id,
    'productid': productId,
    'type': logType,
     'rating': rating,
    'text': text,
     'date': $('#' + logId).attr('date')
};

productLogStore.save(content)
     .then(function onSuccess(answer) {
        console.log (answer);
    })
    .catch(function onError(error) {
        console.log (error);
});

 In case of Firefox V68.0 it jumps into the 'catch' and outputs the error message above.


Now I have to mention there is Business Logic on that collection (POSTSAVE) which is working fine and even does the correct job with no errors in Firefox. Only Firefox has a problem with whatever comes back. I even found out that Firefox has a problem with the response.body:

function onPostSave(request, response, modules) {
  // Any changed log will update the RATING/VISIT in PRODUCTS collection of the product
  
  var logger = modules.logger;
  var log = request.body;
  var sumRating = 0;
  var average = 0;
  
  // Only interested in logs
  if (log.type === 'log') {
    
    // Find all logs of the game
    modules.collectionAccess.collection('gamelogs').find({"productid": log.productid, "type": "log"}, function (err, docs) {
      if (err) {
        // logger.error('Query failed: '+ err);
        response.body = {"state": "nok", "error": err};
        response.error();
      } else {
        // Get all ratings in order to calculate the average
        for (var l = 0; l < docs.length; l++) {
          sumRating += docs[l].rating; 
        }
        // Calculate average
        average = Math.round((sumRating / docs.length) * 10) / 10;
      }

      response.body = {"state": "ok", "rating": average, "visit": docs.length};
      response.continue();
      
      logger.info("donner");
      // Update product by rating and visitors (logs)
      modules.collectionAccess.collection("products").update({"_id": log.productid}, {"$set": { "product.rating": average, "product.visit": docs.length} }, function(err, result) {
        if (err) {
          // logger.error('Update failed: ' + err);
          response.body = {"state": "nok", "error": err};
          response.error();
        }
      });
    });
  } 
  else {
    // Notes (not interested
    response.complete(200);
  }
}

 As soon as I remark the this line in the Business Logic it works fine with no error in Firefox:

response.body = {"state": "ok", "rating": average, "visit": docs.length};

 

Do you see a workaround that still returns the required values and will not lead into an error in Firefox?


Regards


Just tested on a different Android mobile device with Firefox 64.0.2 : Same problem (error message)

Ha! I've found a workaround that works in all browsers:


Attach the response to a sub-object like this:

response.body.cloud = {...};

  Instead of:

response.body = {...};

I've tested this workaround in all browsers (Chrome, Firefox, Safari) and it works. Consider to catch the response the same way on client-side: 

productLogStore.save(content)
    .then(function onSuccess(answer) {
        var response = answer.cloud;
        ....

Regards 

Login or Signup to post a comment