【问题标题】:context.log from request function in node azure function giving warning来自节点 azure 函数中请求函数的 context.log 给出警告
【发布时间】:2020-02-25 12:51:59
【问题描述】:

我创建了调用 GET Api 的 Timer Trigger Azure 函数。 但它会发出请求警告并且不显示输出

代码

var request = require('request');

module.exports = async function (context, myTimer) {

   request(<API_ENDPOINT_GET>', function (error, response, body) {

        if (error) {
            context.log(error);
        } 
        if (!error && response.statusCode == 200) {
            context.log(body) 
        }
        context.done();
    });
};

警告:

函数执行完成后对上下文对象的“日志”意外调用。请检查未等待的异步调用或在函数执行完成之前对“完成”的调用。函数名称:TimerTrigger。

【问题讨论】:

    标签: node.js azure azure-functions serverless


    【解决方案1】:

    问题是您将异步与回调(请求)混合在一起。请查看this thread 了解更多信息。因此,您应该将您的请求转换为异步/等待模式。请查看this article,其中显示了您可以使用的一些替代方案。

    【讨论】: