0
votes

There have been questions about this topic in previous years, but Ember has changed a lot since then and most of those answers were fill ins until things were more 'together'. I am working on an app that is using ember-cli. On the api, if you request a resource from the api that does not exist, the api returns a 404. However, ember data seems to just throw an error upon receiving a 404.

I saw one approach that seemed promising, someone answered a similar question in 2014 and had this code sample:

return this.store.find('matter', params.matter_id).then(
        (function (_this) {
            return function(model){
                resolve(model);
            }
        })(this),
        (function (_this) {
            return function(invalid){
                _this.transitionTo('auth.denied');
            }
        })(this));

ember promises can take a resolve and reject as arguments. In the above code, he passed self instantiating functions as the resolve and reject arguments. The reject is working just as I would like it to. However, now the issue that I am running into is that when I am in the resolve, even though the 'model' variable comes back with an ember data object, i cannot seem to get this to resolve properly. Ember throws and error stating, "Expected an object as data in a call to push for matter , but was undefined".

I was hoping someone out there in the Ember community might have some insight in either how to get this to resolve properly, or perhaps a better way to approach this problem altogether.

1
resolve isn't defined there...Kingpin2k

1 Answers

0
votes

this.store.find returns a promises.

Try doing something like

this.store.find(...).then(function(model) {
  console.log(model);
  resolve(model)
}, function(reason) {
  alert('error');
});

Is the model json, if not it's probably the problem?