मैं superagent के साथ es6 वादों का उपयोग करने का प्रयास कर रहा हूँ। मैं ऐसे फ़ंक्शन को कॉल करने का प्रयास कर रहा हूं जिसमें एक शानदार अनुरोध है जिसमें अंदर लपेटा गया है।वादा करता है es6 और superagent
Request.post(buildReq).then(res => {
if (res.ok) {//process res}
});
यहाँ समारोह रैपिंग superagent
static post(params) {
superagent
.post(params.url)
.send(params.payload)
.set('Accept', 'application/json')
.end((error, res) => {
return this.Promise.resolve(res);
})
.bind(this);
}
जब मैं
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);
})
);
}
को समारोह की वापसी को बदलने मैं एक त्रुटि
enter code here Uncaught TypeError: Cannot read property 'then' of undefined
हो रही है
ऐसा लगता है कि डेटा मेरे ब्राउज़र के देव उपकरण में वापस आ गया है, लेकिन मैं इसे .then फ़ंक्शन के भीतर नहीं ले सकता। मैं वादे से प्रतिक्रिया कैसे प्राप्त कर सकता हूं।
भयानक समाधान का एक बहुत के लिए इसकी आवश्यकता मामले में एक और अधिक consise संस्करण है,। – Sinux