DS.UnauthorizedError

DS.UnauthorizedError Class

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

Module: ember-data

A DS.UnauthorizedError equates to a HTTP 401 Unauthorized response status. It is used by an adapter to signal that a request to the external API was rejected because authorization is required and has failed or has not yet been provided.

An example use case would be to redirect the user to a log in route if a request is unauthorized:

app/routes/application.js
import Ember from 'ember';
import DS from 'ember-data';

const { UnauthorizedError } = DS;

export default Ember.Route.extend({
  actions: {
    error(error, transition) {
      if (error instanceof UnauthorizedError) {
        // go to the sign in route
        this.transitionTo('login');
        return;
      }

      // ...other error handling logic
    }
  }
});

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

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部