javascript - 错误: "ReferenceError: promise is not defined" adding promise to my code

标签 javascript node.js soap

我有 3 个从 Node.js 进行的 Web 服务调用。 2 是 ReST,1 是 SOAP。一切都包含在 Promise 中。

我收到了正确返回 Promise 的 ReST 请求,并且可以在 Promise.all block 中访问这些 Promise,但是当我添加 SOAP 请求时,我收到一条消息,指出 Promise 未定义。

我使用的是 Node v8.2.1。我尝试过请求和请求 promise ,但发生了同样的事情。我的代码看起来像这样 - 我明显做错了什么?

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
    })

添加 soapPromise 内容给了我:

ReferenceError: promise is not defined

最佳答案

删除 returnpromise; 行。您不需要从 Promise 执行器返回任何内容(您提供 new Promise 的回调),并且它不会创建 promise 变量。因此,此时 promise 是一个未定义的标识符,因此出现 ReferenceError

关于javascript - 错误: "ReferenceError: promise is not defined" adding promise to my code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45483238/

相关文章:

javascript - 通过逐行读取检查 Nodejs 中的文件结尾

java - 在 org.apache.cxf.binding.soap.SoapMessage 中获取 SOAP 体中的特定字段

PHP SoapClient __getFunctions() 返回未知类型

javascript - PHP REST 服务器 - AJAX - JSON

javascript - Chrome 在 head 脚本完成之前显示 body

javascript - 从 jQuery Mobile 更改默认数据主题

Javascript:鼠标悬停/鼠标悬停在链接上时更改图像和文本

node.js - Node 和浏览器中的 Webpack 外部

eclipse - 在 Eclipse 中构建 NodeJs 应用程序

java - 如何避免消息 : "Operation getFaultSubCodes not supported by SOAP 1.1" with CXF