I have a router which expects the id and the slug for a page model:
this.route('page',{path:'/page/:slug/:id'});
In my model hook for the page route I am using this.store.query:
return this.store.query("page", {
filter: {
slug: params.slug,
id: params.id
}
}).then(function (result) {
return result.get("firstObject");
});
All good.
However, there are 2 issues with this set up:
Firstly, if I enter a url such as /page/some-name (and omit the id) I expected to be taken to the error route and template - but what I get is:
uncaught exception: unrecognizedURLError
Why don’t we get redirected to the error.hbs template as you would expect to if you try to use an invalid route?
Secondly, if I enter a url which I know will generate an error on my back end, eg /page/some-slug/222 to which I respond with a 404, and I generate this response:
{"errors":[{"detail":"Not found.","source":{"pointer":"/data"},"status":"404"}]}
If I set up an error action on the application route
actions: {
error: function(error,transition) {
this.transitionTo('error');
}
The transition doesn’t work, and I can’t console log out anything useful such as the error code or status.
So I’m not able currently to respond to this. I’ve looked at error substates, but with no joy. Ideally I want to redirect to an error page (error.hbs) already exists, and give the correct 404 error message.
Any help much appreciated!