jonsamwell / angular-http-batcher

Enables HTTP batch request with AngularJS
MIT License
96 stars 28 forks source link

BatchRequestManager sendFn - $digest error. #39

Open ismael-texidor opened 7 years ago

ismael-texidor commented 7 years ago

I keep getting a digest error when this function runs. I added a timeout to make sure the digest is completed prior to running the callback function. Would you consider adding this timeout to the batcher?

function sendFn() {
  var self = this,
    adapter = self.getAdapter(),
    httpBatchConfig = adapter.buildRequest(self.requests, self.config);

  self.sendCallback();
  self.$injector.get('$http')(httpBatchConfig).then(function (response) {
    var batchResponses = adapter.parseResponse(self.requests, response, self.config);

    //timeout I inserted. 
    self.$timeout(function() {
      angular.forEach(batchResponses, function (batchResponse) {
        batchResponse.request.callback(
          batchResponse.statusCode,
          batchResponse.data,
          convertHeadersToString(batchResponse.headers),
          batchResponse.statusText);
      });
    },0,true);
  }, function (err) {
    angular.forEach(self.requests, function (request) {
      request.callback(err.statusCode, err.data, err.headers, err.statusText);
    });
  });
}