DS.NotFoundError

DS.NotFoundError Class

Defined in: addon/adapters/errors.js:278

Module: ember-data

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
import Ember from 'ember';
import DS from 'ember-data';

const { NotFoundError } = DS;

export default Ember.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;
      }
    }
  }
});

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/data/classes/DS.NotFoundError.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部