Error while processing route while working on EAK to CLI migration of Route Model with Promise.all


#1

I have an EAK app which I upgraded for ember 1.10 and am now attempting to migrate to CLI. In my Route model(), I assemble 2 data objects in ‘requests’, then pass that into Promise.all() to be returned in a new object. EAK uses api-stub, but with CLI I’m using ‘ember-cli-api-stub-static’ and I’ve confirmed that the JSON data is served up. With this framework I often get ‘error for this or that’ with no clue as to why. What is it about CLI that makes this block of code fail to work? How can I debug to find the root cause?

model: function(params){

var requests = [ 
  new Ember.RSVP.Promise(function(resolve, reject){
    Ember.$.getJSON('/ota/desc').done(function(data){
        resolve(Ember.Object.create(data));
      }).fail(function(error){
        reject(error);
      });
  }),
  new Ember.RSVP.Promise(function(resolve,reject){
    Ember.$.getJSON('/api/configuration').done(function(data){
        resolve(Ember.Object.create(data));
      }).fail(function(error){
        reject(error);
      });
  })
];
return Ember.RSVP.Promise.all(requests, "Resolving data")
  .then(function (data) {
    return Ember.Object.create({
      descriptiveContents: data[0],
      configuration: data[1]
    });
});

}


#2

I can see the AJAX GET in the console, with 200 OK response, yet the function goes to the ‘fail’ rather than the ‘done’ handler. For testing, I got rid of all the Promise stuff and just have a simple getJSON call inside the model which consoles out from the ‘done’ and ‘fail’ handlers and it always goes to the ‘fail’.


#3

I changed my stub JSON to just { ‘key’:‘val’ } and the basic getJSON works, so now am looking into why my other test JSON is a problem.


#4

It took a while but I found my issue. In my big test JSON, I had ‘"@TimeStamp": Date.create().toISOString()’, which prolly fails in the new version becasue it can’t make the ‘Date.create()’ call for some reason. In my small test JSON, I had ‘"@TimeStamp": ‘2015-04-03’’, which prolly failed becasue it doesn’t like the mix of single quote & double quote.