Class NotFoundError
Extends: | AdapterError |
---|---|
Defined in: | ../adapter/addon/error.js:275 |
Module: | @ember-data/adapter |
A 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
import Route from '@ember/routing/route'; import { NotFoundError } from '@ember-data/adapter/error'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; export default class PostRoute extends Route { @service store; model(params) { return this.get('store').findRecord('post', params.post_id); } @action 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; } } }
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember-data/3.25/classes/NotFoundError