如果我的自定义资源提供程序希望将自定义失败消息返回给ARM,那么我的响应主体应该是什么? 我有一个由JavaScript Azure函数支持的自定义资源提供程序 我尝试了以下
body = {
error: {
code: "Failed",
message: "A custom error message'."
}
};
httpStatus = 200;
context.res = {
status: httpStatus,
headers: {
'Content-Type': 'application/json'
},
body: body
};
ARM模板部署失败,并显示错误-
{
"error": {
"code": "ResourceDeploymentFailure",
"message": "The response for resource had empty or invalid content."
}
我也尝试过
body = {
properties: {
provisioningState: "Failed",
error: {
code: "Failed",
message: "A custom error message'."
}
}
};
httpStatus = 200;
context.res = {
status: httpStatus,
headers: {
'Content-Type': 'application/json'
},
body: body
};
ARM模板部署失败并显示错误
"The resource operation completed with terminal provisioning state 'Failed"
我希望ARM模板部署失败,并显示一条自定义错误消息,我从Azure函数返回“自定义错误消息”。
编辑:
这是我的ARM模板
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourcePrefix": {
"type": "string",
"defaultValue": "prfx-",
"maxLength": 6,
"metadata": {
"description": "The prefix of HLF resource."
}
},
"randomGuid": {
"defaultValue": "[newGuid()]",
"type": "string",
"metadata": {
"description": "New random GUID"
}
}
},
"variables": {
"funcName": "[concat(parameters('resourcePrefix'), substring(parameters('randomGuid'), 0, 5))]",
"myResourceProvider": "my-custom-provider",
"location": "[resourceGroup().location]"
},
"resources": [
{
"apiVersion": "2018-09-01-preview",
"type": "Microsoft.CustomProviders/resourceProviders",
"name": "[variables('myResourceProvider')]",
"location": "[variables('location')]",
"properties": {
"resourceTypes": [
{
"name": "deploy",
"routingType": "Proxy",
"endpoint": "<azure-func-url>"
}
]
}
},
{
"apiVersion": "2018-09-01-preview",
"type": "Microsoft.CustomProviders/resourceProviders/deploy",
"name": "[concat(variables('myResourceProvider'), '/', variables('funcName'))]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.CustomProviders/resourceProviders/',variables('myResourceProvider'))]"
]
}
],
"outputs": {
}
}
答案 0 :(得分:2)
自定义提供程序当前不支持按原样代理错误消息。自定义错误消息将作为详细信息嵌套在标准消息下。
但是,似乎有一个错误正在阻止该错误通过ARM模板的传播。这应该尽快解决!
答案 1 :(得分:0)
@jjbfour是正确的。自定义消息嵌套在传播的消息中的“下游”标签下。但这对我很好。以下作品
seen
我之前犯的错误没有正确设置HTTP状态。