How to handle 404 of Ember Data in route?

后端 未结 3 1540
借酒劲吻你
借酒劲吻你 2021-02-15 16:42

In my route I have a method that tries to request a list of models from the server

 model: ->
    App.MyModel.find
      projectId: (@modelFor \"project\").id         


        
3条回答
  •  孤街浪徒
    2021-02-15 17:23

    Bad news: right now, ember-data doesn't do anything when it gets a 404 on find(). At all. The model sits in the 'loading' state forever.

    There are no non-completely-stupid options, here, in my opinion. What I would probably do as a last resort is add a notFound attribute on my DS.Model, and instead of returning 404, return JSON with notFound set to true. It's painful, I know...

    --- I had originally offered a solution of overriding find in a subclass of RESTAdapter. Then I noticed that find DOES NOT get passed the record instance it is supposedly loading. So, no go on handling 404s by putting the record into an error state.

    [NOTE: ember-data has changed dramatically since March 2013, the information in this answer may no longer be operative]

提交回复
热议问题