2017-05-30 12 views
1

my apiとember-cli-mirageを使用する間の応答の不一致を理解しようとしています。XHRオブジェクトにember-cli-mirage応答ヘッダーがありません

ユーザーを認証するPOST要求に対する応答を待っているハンドラーがあります。ハンドラの予想パラメータは、response,statusおよびxhr

(たとえば、.then(function(response, status, xhr) {...})です。

私のAPIを使用して、私は期待していたものを受け取ります。レスポンスはデータ、statusはstatusText、xhrはxhrオブジェクトです。しかし、ember-cli-mirageを使用すると、すべてが応答(種類)の下にあり、statusとxhrはどちらも定義されていません。

私のコードのスニペットは以下の通りです:

蜃気楼/ config.jsの

this.post(URI.AUTH_SIGN_IN, function(db, request) { 
    const responseHeaders = { 
    'access-token': 'abcxyz123', 
    'client': 'foobarbaz', 
    'token-type': 'Bearer', 
    'expiry': '1497364419', 
    'uid': '[email protected]' 
    }; 

    const user = { 
    data: { id: 1, type: 'user', attributes: { uid: '[email protected]', email: '[email protected]', name: 'John Doe', provider: 'email' } } 
    }; 

    return new Mirage.Response(200, responseHeaders, user); 
}); 

のオーセンティケータ/ devise.js

authenticate(identification, password) { 
    ... 
    this.makeRequest(credentials).then(function(response, status, xhr) { 
    // persists the five headers needed to send to devise-token-auth 
    // with mirage; response = Response {type: "default", status: 200, ok: true, statusText: "OK", headers: Headers…}, status = undefined, xhr = undefined 
    // with actual api; response = Object {data: Object}, status = "success", xhr = Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function…} 

    // As a result below will fail :( 
    // TypeError: Cannot read property 'getResponseHeader' of undefined 
    var result = { 
     'access-token': xhr.getResponseHeader('access-token'), 
     expiry:   xhr.getResponseHeader('expiry'), 
     tokenType:  xhr.getResponseHeader('token-type'), 
     uid:   xhr.getResponseHeader('uid'), 
     client:   xhr.getResponseHeader('client') 
     }; 
    }); 
} 

私はそれをやっていると信じて私は間違っていると知られています:)。どんな助けも大歓迎です。

+0

この@TomDoeに関するニュースはありますか? –

答えて

0

ええと、makeRequestが2番目と3番目のパラメータでなぜ未定義に戻っているのか分かりません。

私はシンプルなひねりを作り、argsがgetJSONのために正しいようだ:

https://ember-twiddle.com/70229e352f37b4e437ced8509a4415d9?openFiles=routes.application.js%2C

model() { 
    return Ember.$.getJSON('/foo').then((data, response, object) => { 
    return object.getAllResponseHeaders(); 
    }); 
} 

ありプリテンダーは嘲笑応答を処理する方法と若干異なるものになるか、どのようにmakeRequest作品をiwthも、そうIそこを見ることから始めることを提案する。

+0

これは 'ember-fetch'の結果です。https://github.com/simplabs/ember-simple-auth/blob/1.3.0/addon/authenticators/devise.js#L202。 @marcoowそれが原因かもしれないかどうか知っていますか?繰り返しますが、どんな助けでも大変感謝しています。どうも –

関連する問題