Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

ember.js - Ember-Data handling 401’s

Any thoughts on handling 401 errors?

In the application initializer I'm deferring readiness and fetching the current user via ember-data. If I receive a 401 the app dies and becomes unusable. I'd like to handle this error, and then advancereadiness. I cant seem to find a workaround for this. Any info would be appreciated!

Gist here: https://gist.github.com/unknpwn/6126462

I noticed there was a similar topic here, but it seems to be out of date.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The previous answer is outdated. In current Ember version (1+) events are deprecated and you should use actions object (instead of function).

Ember example:

App.ApplicationRoute = Ember.Route.extend({
  actions: {
    error: function(err) {
      // error handler called in case of an error.
      // show the error message to user here
      // or transition to another route
    }
  }
});

Ember CLI example:

import Ember from 'ember';

export default Ember.Route.extend({
  actions: {
    error: function(err) {
      // error handler called in case of an error.
      // show the error message to user here
      // or transition to another route
    }
  }
});

With these action handlers the error will bubble nicely to the main application route if you don't stop it before in your route.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...