Model does not exist (http 404 not found) #296

Closed
pjlammertyn opened this Issue Jun 21, 2012 · 26 comments

Comments

Projects
None yet
@pjlammertyn

if you try to find an object by id

App.store.find(App.Firm, 54)

and the rest server returns a 404 not found, the model remains in the loading state.
It would be better if goes to an error state.

a solution is to extend the rest_adapter

    find: function(store, type, id) {
        var root = this.rootForType(type);

        this.ajax(this.buildURL(root, id), "GET", {
            success: function(json) {
                this.sideload(store, type, json, root);
                store.load(type, json[root]);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                store.load(type, id, 'error');
                //do some aditional stuff to set the model in an error state or modify the load state
            }
        });
    }

any suggestions?

@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Jun 22, 2012

Member

In my #298 PR I propose to pass record instance to find method, this way we could pass it along to error handeling code

Member

tchak commented Jun 22, 2012

In my #298 PR I propose to pass record instance to find method, this way we could pass it along to error handeling code

@wagenet

This comment has been minimized.

Show comment
Hide comment
@wagenet

wagenet Oct 18, 2012

Member

@pjlammertyn, @tchak I suspect this has been resolved in master. Can you verify?

Member

wagenet commented Oct 18, 2012

@pjlammertyn, @tchak I suspect this has been resolved in master. Can you verify?

@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Oct 18, 2012

Member

definitely not solved. We have no error handeling at all.

Member

tchak commented Oct 18, 2012

definitely not solved. We have no error handeling at all.

@martijnwalraven

This comment has been minimized.

Show comment
Hide comment
@martijnwalraven

martijnwalraven Feb 11, 2013

I was wondering what the current thinking about error handling on find is, when receiving a 404 or 403 response for example. Some error handling on create and update has been added in #476 but there is no handling at all on find.

I tried implementing the suggestion @tchak made above of passing a record to the adapter find method. Reusing the existing error handling code in the adapter sends a becameError to the record however, and there is no handler for that in the loading state. If I add a handler to the state machine, the record gets to the error state but even that doesn't seem to affect the router.

I'm just getting started with Ember, so I only understand bits and pieces of the architecture, but I was expecting a transition from the loading route to the failure route. Does that make sense? What can I do to make that work?

I was wondering what the current thinking about error handling on find is, when receiving a 404 or 403 response for example. Some error handling on create and update has been added in #476 but there is no handling at all on find.

I tried implementing the suggestion @tchak made above of passing a record to the adapter find method. Reusing the existing error handling code in the adapter sends a becameError to the record however, and there is no handler for that in the loading state. If I add a handler to the state machine, the record gets to the error state but even that doesn't seem to affect the router.

I'm just getting started with Ember, so I only understand bits and pieces of the architecture, but I was expecting a transition from the loading route to the failure route. Does that make sense? What can I do to make that work?

@martijnwalraven

This comment has been minimized.

Show comment
Hide comment
@martijnwalraven

martijnwalraven Feb 11, 2013

Thinking about this some more, there doesn't seem to be a way to indicate an error state for a RecordArray at all. So how should errors on find methods that return more than one record be handled?

Thinking about this some more, there doesn't seem to be a way to indicate an error state for a RecordArray at all. So how should errors on find methods that return more than one record be handled?

@stephanos

This comment has been minimized.

Show comment
Hide comment
@stephanos

stephanos Mar 23, 2013

This is really bad news. I mean 404s can happen all the time, ember-data is almost useless without handling 404s (I would know, I just ran into this issue and have NO idea how to solve it).

This is really bad news. I mean 404s can happen all the time, ember-data is almost useless without handling 404s (I would know, I just ran into this issue and have NO idea how to solve it).

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 24, 2013

Member

@stephanos we are aware of this shortcoming.

The current plan is: https://gist.github.com/stefanpenner/9ccb0503e451a9792ed0
Work has begun, expect at least the above mentioned issue to be resolved within the next few days.

Member

stefanpenner commented Mar 24, 2013

@stephanos we are aware of this shortcoming.

The current plan is: https://gist.github.com/stefanpenner/9ccb0503e451a9792ed0
Work has begun, expect at least the above mentioned issue to be resolved within the next few days.

@stephanos

This comment has been minimized.

Show comment
Hide comment
@stephanos

stephanos Mar 24, 2013

thank you for the update, I appreciate it

thank you for the update, I appreciate it

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 24, 2013

Member

@stephanos yes this is annoying, I have a branch of ember-data that abrasively forces this to work. I'll try to get a less janky solution in ASAP.

Member

stefanpenner commented Mar 24, 2013

@stephanos yes this is annoying, I have a branch of ember-data that abrasively forces this to work. I'll try to get a less janky solution in ASAP.

@ghost ghost assigned stefanpenner Mar 24, 2013

@Emerson

This comment has been minimized.

Show comment
Hide comment
@Emerson

Emerson Apr 21, 2013

Any updates on this? No error handling on .find() is killing me.

Emerson commented Apr 21, 2013

Any updates on this? No error handling on .find() is killing me.

@pharcosyle

This comment has been minimized.

Show comment
Hide comment
@pharcosyle

pharcosyle Jun 25, 2013

+1

Really need this. Currently don't have a good way of handling it when users go to a mistyped URL with a dynamic segment ID and the model can't be found

+1

Really need this. Currently don't have a good way of handling it when users go to a mistyped URL with a dynamic segment ID and the model can't be found

@jasonkriss

This comment has been minimized.

Show comment
Hide comment
@jasonkriss

jasonkriss Jun 27, 2013

Contributor

@stefanpenner what's the latest thinking on this? With the new router facelift, it'd be really great if we could push forward on improving the promise support in ember data. There was some good discussion on discourse, but that seems to have stagnated. #1046 is also relevant here, but probably isn't a long-term solution imo.

Contributor

jasonkriss commented Jun 27, 2013

@stefanpenner what's the latest thinking on this? With the new router facelift, it'd be really great if we could push forward on improving the promise support in ember data. There was some good discussion on discourse, but that seems to have stagnated. #1046 is also relevant here, but probably isn't a long-term solution imo.

@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Jun 27, 2013

Member

@jasonkriss #1046 is a playground for now. A better solution long term is probably to always return promises from find method.

Member

tchak commented Jun 27, 2013

@jasonkriss #1046 is a playground for now. A better solution long term is probably to always return promises from find method.

@jasonkriss

This comment has been minimized.

Show comment
Hide comment
@jasonkriss

jasonkriss Jun 27, 2013

Contributor

@tchak Yep, I'm with you. Thanks a lot for putting it out there. It's definitely helpful, as is all the rest of promise work you've done. Much appreciated.

Contributor

jasonkriss commented Jun 27, 2013

@tchak Yep, I'm with you. Thanks a lot for putting it out there. It's definitely helpful, as is all the rest of promise work you've done. Much appreciated.

@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Jun 27, 2013

Member

@jasonkriss this is a sum of my current ideas https://gist.github.com/tchak/5875101

Member

tchak commented Jun 27, 2013

@jasonkriss this is a sum of my current ideas https://gist.github.com/tchak/5875101

@commadelimited

This comment has been minimized.

Show comment
Hide comment
@commadelimited

commadelimited Jul 17, 2013

I'll 👍 this. I attempted to add an error event per some of the solutions in this SO post but the event never fired for my route.

I'll 👍 this. I attempted to add an error event per some of the solutions in this SO post but the event never fired for my route.

@pharcosyle

This comment has been minimized.

Show comment
Hide comment
@pharcosyle

pharcosyle Jul 21, 2013

Wouldn't the error event on the router only be fired if the promise from a model() call (in this case, an ember-data record) rejects? I'd like some way to respond whenever the server can't find() a record.

Wouldn't the error event on the router only be fired if the promise from a model() call (in this case, an ember-data record) rejects? I'd like some way to respond whenever the server can't find() a record.

@pjlammertyn pjlammertyn reopened this Jul 22, 2013

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Jul 22, 2013

Member

@pharcosyle this is part of a larger issue, we currently mix the models promise and the operation that retrieves it, this leads to many issues. We have a plan and early spec'd out proposal for dealing with these scenarios across ember. Expect something on discuss.emberjs.com soon.

Member

stefanpenner commented Jul 22, 2013

@pharcosyle this is part of a larger issue, we currently mix the models promise and the operation that retrieves it, this leads to many issues. We have a plan and early spec'd out proposal for dealing with these scenarios across ember. Expect something on discuss.emberjs.com soon.

@pharcosyle

This comment has been minimized.

Show comment
Hide comment
@pharcosyle

pharcosyle Jul 23, 2013

@stefanpenner gotcha, I'll keep an eye out!

@stefanpenner gotcha, I'll keep an eye out!

@OpakAlex OpakAlex referenced this issue in Zatvobor/ember-couchdb-kit Jul 29, 2013

Closed

Model does not exist (http 404 not found) #32

@wycats

This comment has been minimized.

Show comment
Hide comment
@wycats

wycats Sep 3, 2013

Member

This should be solved now.

Member

wycats commented Sep 3, 2013

This should be solved now.

@wycats wycats closed this Sep 3, 2013

@jdurand

This comment has been minimized.

Show comment
Hide comment
@jdurand

jdurand May 1, 2015

I'm experiencing this issue with 1.0.0-beta.16.1

jdurand commented May 1, 2015

I'm experiencing this issue with 1.0.0-beta.16.1

@igorT

This comment has been minimized.

Show comment
Hide comment
@igorT

igorT May 2, 2015

Member

Could you submit a failing jsbin or a test case? You can find starting jsbins in https://github.com/emberjs/data/blob/master/CONTRIBUTING.md

Member

igorT commented May 2, 2015

Could you submit a failing jsbin or a test case? You can find starting jsbins in https://github.com/emberjs/data/blob/master/CONTRIBUTING.md

@jdurand

This comment has been minimized.

Show comment
Hide comment
@jdurand

jdurand May 3, 2015

Here's the JS Bin :
http://emberjs.jsbin.com/juzikujohe/1/edit?js,output

If you click on Inspect Authors after trying to access Arthur C. Clarke you'll see that the record is in the store even though the adapter returned a 404.

jdurand commented May 3, 2015

Here's the JS Bin :
http://emberjs.jsbin.com/juzikujohe/1/edit?js,output

If you click on Inspect Authors after trying to access Arthur C. Clarke you'll see that the record is in the store even though the adapter returned a 404.

@pangratz

This comment has been minimized.

Show comment
Hide comment
@pangratz

pangratz May 4, 2015

Member

If you click on Inspect Authors after trying to access Arthur C. Clarke you'll see that the record is in the store even though the adapter returned a 404.

@jdurand I think this is related to #3013 (comment)

Member

pangratz commented May 4, 2015

If you click on Inspect Authors after trying to access Arthur C. Clarke you'll see that the record is in the store even though the adapter returned a 404.

@jdurand I think this is related to #3013 (comment)

@jdurand

This comment has been minimized.

Show comment
Hide comment
@jdurand

jdurand May 4, 2015

@pangratz Yep, seems spot on. Thanks for linking!

jdurand commented May 4, 2015

@pangratz Yep, seems spot on. Thanks for linking!

@jdurand

This comment has been minimized.

Show comment
Hide comment
@jdurand

jdurand May 11, 2015

Looks like #3043 fixed this (for real) @pangratz 👍

jdurand commented May 11, 2015

Looks like #3043 fixed this (for real) @pangratz 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment