context.log 来自节点 azure 函数中的请求函数发出警告

context.log from request function in node azure function giving warning

我创建了调用 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();
    });
};

警告:

函数执行完成后对上下文对象的 'log' 意外调用。请检查未等待的异步调用或函数执行完成前对 'done' 的调用。函数名称:TimerTrigger.

问题是您将异步与回调(请求)混合在一起。请查看 this thread for more information. So, you should convert your request to async/await pattern. Please have a look to this article 显示的一些您可以使用的替代方法。