如何在azure函数中触发失败http触发器,带有自定义错误响应

我无法find一个方法来调用一个nodejs azure函数的http调用,并且包含一个自定义的错误响应。

调用context.done()允许自定义响应(但不会在Application Insights中指示为失败)

调用context.done(true,XXX)确实会创build一个失败,但会向用户返回一个通用错误(不pipe我放在XXX中):

{"id":"b6ca6fb0-686a-4a9c-8c66-356b6db51848","requestId":"7599d94b-d3f2-48fe-80cd-e067bb1c8557","statusCode":500,"errorCode":0,"message":"An error has occurred. For more information, please check the logs for error ID b6ca6fb0-686a-4a9c-8c66-356b6db51848"} 

这只是我尝试在Azure funcs上运行快速web api而遇到的最新的头痛。 如果你不能跟踪错误,那么它就不应该被称为“应用程序见解”。 有任何想法吗?

成功将是真实的,但resultCode将被设置为您的价值。

试试这样的AppInsights查询:

 // Get all errors requests | where toint(resultCode) >= 400 | limit 10 

[更新]请求中的Id值是“函数实例ID”,它唯一标识了该调用。

还有一个“跟踪”表,其中包含来自您的天青function的日志消息。 您可以通过operation_Id在请求和跟踪之间进行连接。

 requests | where toint(resultCode) >= 400 | take 10 | join (traces) on operation_Id | project id, message, operation_Id 

响应正文不会自动logging到AppInsights。 您需要添加一些明确的日志语句来捕获。

为什么不使用context.res来为HTTP触发器函数返回客户响应?

在这里输入图像说明