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:

ReferenceError: promise is not defined

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 0
Add a ment  | 

1 Answer 1

Reset to default 3

Remove 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.

本文标签: javascriptError quotReferenceError promise is not definedquot adding promise to my codeStack Overflow