在Ember.js中处理403
如果用户从我的API收到403,我想将其重定向到在Ember.js中处理403,ember.js,Ember.js,如果用户从我的API收到403,我想将其重定向到/login。以下是我的/app/routes/application.js中的内容: import Ember from 'ember'; import ApplicationRouteMixin from 'ember-simple-auth-auth0/mixins/application-route-mixin'; export default Ember.Route.extend(ApplicationRouteMixin, { a
/login
。以下是我的/app/routes/application.js中的内容:
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth-auth0/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
error(error, transition) {
if (error.status === '403') {
this.replaceWith('login');
} else {
return true;
}
}
}
});
但这似乎不能很好地处理余烬数据,当返回403时,会引发异常,但路由器不会处理,有什么提示吗?您可以覆盖余烬数据应用程序适配器以捕获403。然后,在那里执行操作可以让您根据需要处理触发重定向的事情:
// app/adapters/application.js
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
handleResponse(status, headers, payload, requestData) {
if(status === 403) {
// throw an error to be caught at the app level
// or work with a service to handle things as desired
}
return this._super(status, headers, payload, requestData);
}
});
你能给我举个例子吗?我不确定我是否理解。当然,只是更新。这应该能解决你的问题。