我正在使用以下代码,它会引发如下所示的错误
执行“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"
};
}
};