Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

pjlammertyn opened this issue Jun 21, 2012 · 26 comments
Labels
Bug
Milestone

Comments

@pjlammertyn
Copy link

@pjlammertyn pjlammertyn commented Jun 21, 2012

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
Copy link
Member

@tchak 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
Copy link
Member

@wagenet wagenet commented Oct 18, 2012

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

@tchak
Copy link
Member

@tchak tchak commented Oct 18, 2012

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

@martijnwalraven
Copy link

@martijnwalraven martijnwalraven commented 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?

@martijnwalraven
Copy link

@martijnwalraven martijnwalraven commented 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?

@stephanos
Copy link

@stephanos stephanos commented 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).

@stefanpenner
Copy link
Member

@stefanpenner 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
Copy link

@stephanos stephanos commented Mar 24, 2013

thank you for the update, I appreciate it

@stefanpenner
Copy link
Member

@stefanpenner 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
Copy link

@Emerson Emerson commented Apr 21, 2013

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

@pharcosyle
Copy link

@pharcosyle pharcosyle commented 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

@jasonkriss
Copy link
Contributor

@jasonkriss 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
Copy link
Member

@tchak 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
Copy link
Contributor

@jasonkriss 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
Copy link
Member

@tchak tchak commented Jun 27, 2013

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

@commadelimited
Copy link

@commadelimited commadelimited commented 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.

@pharcosyle
Copy link

@pharcosyle pharcosyle commented 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.

@pjlammertyn pjlammertyn reopened this Jul 22, 2013
@stefanpenner
Copy link
Member

@stefanpenner 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
Copy link

@pharcosyle pharcosyle commented Jul 23, 2013

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

@wycats
Copy link
Member

@wycats wycats commented Sep 3, 2013

This should be solved now.

@wycats wycats closed this Sep 3, 2013
@jdurand
Copy link

@jdurand jdurand commented May 1, 2015

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

@igorT
Copy link
Member

@igorT 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
Copy link

@jdurand 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
Copy link
Member

@pangratz 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
Copy link

@jdurand jdurand commented May 4, 2015

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

@jdurand
Copy link

@jdurand 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.