Class DS.NotFoundError
A DS.NotFoundError
equates to a HTTP 404 Not Found
response status.
It is used by an adapter to signal that a request to the external API
was rejected because the resource could not be found on the API.
An example use case would be to detect if the user has entered a route for a specific model that does not exist. For example:
app/routes/post.js | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import Route from '@ember/routing/route'; import DS from 'ember-data'; const { NotFoundError } = DS; export default Route.extend({ model(params) { return this.get('store').findRecord('post', params.post_id); }, actions: { error(error, transition) { if (error instanceof NotFoundError) { // redirect to a list of all posts instead this.transitionTo('posts'); } else { // otherwise let the error bubble return true; } } } }); |