スーパーエージェントで es6 の約束を使用しようとしています。スーパーエージェントのリクエストがラップされた関数を呼び出そうとしています。
Request.post(buildReq).then(res => {
if (res.ok) {//process res}
});
これが関数ラッピングスーパーエージェントです
static post(params) {
superagent
.post(params.url)
.send(params.payload)
.set('Accept', 'application/json')
.end((error, res) => {
return this.Promise.resolve(res);
})
.bind(this);
}
エラーが発生する
enter code here Uncaught TypeError: Cannot read property 'then' of undefined
関数の戻り値をに変更すると
static post(params) {
return Promise.resolve(superagent
.post(params.url)
.auth(params.auth.username, params.auth.password)
.send(params.payload)
.set('Accept', 'application/json')
.end((error, res) => {
return this.Promise.resolve(res);
})
);
}
ブラウザの開発ツールでデータが返されたように見えますが、.then 関数内でデータにアクセスできません。約束からの応答を取得するにはどうすればよいですか。