admin管理员组文章数量:1417033
I have 3 web service calls being made from Node.js. 2 are ReST, 1 is SOAP. All are wrapped in Promises.
I've gotten my ReST requests to return the promises correctly and these are accessible in the Promise.all block but when I add my SOAP request, I get a message saying Promise is not defined.
I'm using node v8.2.1. I've tried request and request-promise but the same thing happens. My code looks like this - anything I'm obviously doing wrong?
const locationRequest = require('request');
var soapPromise = new Promise(function(resolve, reject) {
locationRequest(options1, function(error, response, output) {
if (error) {
console.info("soap error: " + error);
reject(error);
}
else {
console.info("soap success: " + response);
resolve(response);
}
});
return promise;
});
Promise.all([restPromise, photoPromise, soapPromise]) //addition of soapPromise causes the issue
.then(function([restResult, photoResult, soapResult]) {
//respond to client
console.info("Resource: " + restResult.name);
console.info("Photo Path: " + photoResult);
console.info("Soap: " + soapResult);
})
.catch(function(error) {
console.info("promise all error: " + error);
res.send('done');
//catch an error generated from either request
})
Adding the soapPromise
stuff gives me:
ReferenceError: promise is not defined
I have 3 web service calls being made from Node.js. 2 are ReST, 1 is SOAP. All are wrapped in Promises.
I've gotten my ReST requests to return the promises correctly and these are accessible in the Promise.all block but when I add my SOAP request, I get a message saying Promise is not defined.
I'm using node v8.2.1. I've tried request and request-promise but the same thing happens. My code looks like this - anything I'm obviously doing wrong?
const locationRequest = require('request');
var soapPromise = new Promise(function(resolve, reject) {
locationRequest(options1, function(error, response, output) {
if (error) {
console.info("soap error: " + error);
reject(error);
}
else {
console.info("soap success: " + response);
resolve(response);
}
});
return promise;
});
Promise.all([restPromise, photoPromise, soapPromise]) //addition of soapPromise causes the issue
.then(function([restResult, photoResult, soapResult]) {
//respond to client
console.info("Resource: " + restResult.name);
console.info("Photo Path: " + photoResult);
console.info("Soap: " + soapResult);
})
.catch(function(error) {
console.info("promise all error: " + error);
res.send('done');
//catch an error generated from either request
})
Adding the soapPromise
stuff gives me:
Share Improve this question edited Aug 3, 2017 at 12:29 T.J. Crowder 1.1m200 gold badges2k silver badges2k bronze badges asked Aug 3, 2017 at 11:45 Ross CoundonRoss Coundon 9271 gold badge12 silver badges20 bronze badges 0ReferenceError: promise is not defined
1 Answer
Reset to default 3Remove the return promise;
line. You're not expected to return anything out of the Promise
executor (the callback you give new Promise
), and it doesn't create a promise
variable. So promise
is an undefined identifier at that point, hence the ReferenceError
.
版权声明:本文标题:javascript - Error: "ReferenceError: promise is not defined" adding promise to my code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745267484a2650691.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论