【发布时间】:2020-12-22 17:52:11
【问题描述】:
我有一个用 JS 编写的 Azure 函数,它由服务总线触发并生成文件到 Blob 存储。当我尝试返回 HTTP 结果时,我收到如下错误:
System.Private.CoreLib: Exception while executing function: Functions.categoryMessageConsumer. Microsoft.Azure.WebJobs.Script: Unable to cast object of type 'System.String' to type 'Microsoft.AspNetCore.Http.HttpRequest'.
我不知道为什么结果试图映射到 HttpRequest 对象。
index.ts:
import { AzureFunction, Context, HttpRequest } from '@azure/functions';
...
const serviceBusTopicTrigger: AzureFunction = async function(context: Context, req: HttpRequest) {
let categoryMessage: CategoryMessage = Object.assign(new CategoryMessage(), req);
let messageValidationResult = await categoryMessage.validate();
if(!messageValidationResult.isValid) {
context.log.error(messageValidationResult.errors);
return {
status: 400,
body: "Unexpected error"
};
}
...
}
function.json 输出绑定:
...
{
"type": "http",
"direction": "out",
"name": "$return"
}
...
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
【问题讨论】:
标签: javascript typescript azure azure-blob-storage