0

我正在使用以下代码,它会引发如下所示的错误

执行“Functions.TranslateFunction”(失败,Id=4cc27692-14a1-4c22-b0b7-7615d9812950)[12/10/2019 10:40:06 AM] System.Private.CoreLib:执行函数时出现异常:Functions.TranslateFunction。System.Private.CoreLib:结果:失败异常:TypeError:context.error 不是函数堆栈:TypeError:context.error 不是 module.exports 中的函数(C:\Users\M1056438\Coding\Functions\TranslateFunction\index .js:26:13) 在 processTicksAndRejections (internal/process/task_queues.js:93:5)。

const axios = require('axios');
module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (req.query.name || (req.body && req.body.name)) {

// Make a QNA maker API call
var postData = {
    question: "Who are you"
  };
  let axiosConfig = {
    headers: {
        'Content-Type': 'application/json',
        "Authorization":"EndpointKey ********"
    }
  };

  try {
    const response =  await axios.post('https://qnamakercommonfordemos.azurewebsites.net/qnamaker/knowledgebases/********/generateAnswer', postData,axiosConfig)
    context.log(`statusCode: ${response.statusCode}`);
    context.log(response);
    context.done();
    return response; // or return a custom object using properties from response
  } catch (error) {
    // If the promise rejects, an error will be thrown and caught here
    context.error(error);
  }


        context.res = {
            // status: 200, /* Defaults to 200 */
            body: response
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
};
4

1 回答 1

0

我认为对象上没有error定义函数context。但是在 context.log 上,可以使用其他日志记录方法,让您可以在其他跟踪级别编写函数日志:

在此处输入图像描述

例如:

context.log.info({hello: 'world'});

context.log.error("An error has occurred.");

有关“上下文”对象的更多详细信息,请阅读此处:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#context-object

所以你可以context.error改为context.log.error

于 2019-12-10T12:35:32.540 回答