2

I cannot seem to get ember-data to reject failed (404's) when using findQuery(..query..); find(..id..); works fine.

So in the route:

App.PostRoute = Ember.Route.extend({

  serialize: function(model, params) {
    return { post_id: model.get('slug') };
  },

  model: function(params){
    var query = {};
    query.slugs = params.post_id;
    return App.Post.findQuery(query).then( 
      function (data) {
        return data.get('firstObject');
      }, 
      function (error) {
        console.log('error');
        throw 'boom!';
      }
    )
  },

  setupController: function(controller, model){
    this.controllerFor('post').set('content', model);
  },

  events: {
    error: function (reason, transition) {
     console.log('Error!');
    }
  }

});

I have also tried this:

return App.Post.findQuery(query).then( function (data) {
  return data.get('firstObject');
}).then( null, function (error) {
  console.log('error');
  throw 'boom!';
});

No joy. I can see the request to the URL returning as 404, but the promises error is never triggered. What am I missing?

i0n
  • 916
  • 1
  • 8
  • 26

1 Answers1

0

I don't know if it's only a typo, but the events hash in your PostRoute should be called events you seam to have defined it as singular event this might be the problem why your error hook inside that hash not getting found and this not invoked:

App.PostRoute = Ember.Route.extend({
  ...
  events: {
    error: function (reason, transition) {
      console.log('Error!');
    }
  }
});

Hope it helps.

intuitivepixel
  • 23,302
  • 3
  • 57
  • 51
  • Hi there! Yes, sadly that was just a typo. I have adjusted the example above. I have tracked this down to a problem with the implementation for findQuery, there is an open PR fixing the issue here: https://github.com/emberjs/data/pull/1096#issuecomment-22246022 – i0n Aug 07 '13 at 16:01
  • @i0n, ok good to know, I saw you actually talking about this with Paul Chavard in the github notification emails, sorry I couldn't help at all. – intuitivepixel Aug 07 '13 at 16:05
  • @i0n @ intuitivepixel did you have any luck figuring this out? I've just [raised this issue](https://github.com/emberjs/ember.js/issues/4461) – bguiz Mar 04 '14 at 05:35