Ember"适配器操作失败"在Ember 2.2.0.beta.3中返回401时出错

时间:2016-01-07 23:25:31

标签: ember.js ember-data

在我的Ember索引路径中,我使用RestAdapter来检索大量的"页面" s:

/routes/index.js

export default Ember.Route.extend({
    model: function() {
        return this.store.findAll('page');
    }
});

当上一个模型调用" page"将失败,错误代码为401(auth失败),我在应用程序路径中捕获错误:

/routes/application.js

export default Ember.Route.extend({
    actions: {
        error: function(reason) {
            console.log('i am in here');
          this.transitionTo('login');
          return false;
        }
    }
});

但是在控制台上,我收到一条令人讨厌的错误消息,即使转换到保护页面(登录)也是如此。

GET http://localhost:4200/api/pages 401 (Unauthorized)send @ jquery.js:9664jQuery.extend.ajax @ jquery.js:9215(anonymous function) @ rest-adapter.js:764initializePromise @ ember.debug.js:52308Promise @ ember.debug.js:54158ember$data$lib$system$adapter$$default.extend.ajax @ rest-adapter.js:729ember$data$lib$system$adapter$$default.extend.findAll @ rest-adapter.js:356ember$data$lib$system$store$finders$$_findAll @ finders.js:123ember$data$lib$system$store$$Service.extend._fetchAll @ store.js:947ember$data$lib$system$store$$Service.extend.findAll @ store.js:923model @ index.js:4_emberRuntimeSystemObject.default.extend.deserialize @ ember.debug.js:25918applyHook @ ember.debug.js:52043HandlerInfo.runSharedModelHook @ ember.debug.js:50251_routerUtils.subclass.getModel @ ember.debug.js:50167(anonymous function) @ ember.debug.js:51911tryCatch @ ember.debug.js:52258invokeCallback @ ember.debug.js:52273publish @ ember.debug.js:52241(anonymous function) @ ember.debug.js:30835Queue.invoke @ ember.debug.js:320Queue.flush @ ember.debug.js:384DeferredActionQueues.flush @ ember.debug.js:185Backburner.end @ ember.debug.js:563Backburner.run @ ember.debug.js:685Backburner.join @ ember.debug.js:705run.join @ ember.debug.js:20147_emberMetalAssign.default.handleEvent @ ember.debug.js:45072exports.default._emberMetalMixin.Mixin.create._Mixin$create.handleEvent @ ember.debug.js:42009exports.default._emberRuntimeSystemObject.default.extend._bubbleEvent @ ember.debug.js:43089(anonymous function) @ ember.debug.js:43031jQuery.event.dispatch @ jquery.js:4670elemData.handle @ jquery.js:4338
application.js:5 i am in here
ember.debug.js:30877 Error: Adapter operation failed
    at new Error (native)
    at Error.EmberError (http://localhost:4200/assets/vendor.js:26437:21)
    at Error.ember$data$lib$adapters$errors$$AdapterError (http://localhost:4200/assets/vendor.js:65986:50)
    at ember$data$lib$system$adapter$$default.extend.handleResponse (http://localhost:4200/assets/vendor.js:67290:16)
    at hash.error (http://localhost:4200/assets/vendor.js:67370:33)
    at fire (http://localhost:4200/assets/vendor.js:3373:30)
    at Object.self.fireWith [as rejectWith] (http://localhost:4200/assets/vendor.js:3485:7)
    at done (http://localhost:4200/assets/vendor.js:9541:14)
    at XMLHttpRequest.callback (http://localhost:4200/assets/vendor.js:9943:8)

实际上我登陆登录页面。但是我如何摆脱"适配器操作失败"错误?

1 个答案:

答案 0 :(得分:0)

我相信您的申请路线return this.transitionTo('login')可能需要return false而不是error。这对我来说过去很有用。