[英]Azure Custom resource provider - custom error message to ARM template
如果我的自定義資源提供程序想要向 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": {
}
}
自定義提供程序當前不支持按原樣代理錯誤消息。 自定義錯誤消息將作為詳細信息嵌套在標准消息下。
但是,看起來有一個錯誤正在阻止錯誤通過 ARM 模板傳播。 這應該很快修復!
@jjbfour 是對的。 自定義消息嵌套在傳播的消息中的“下游”標簽下。 但這對我來說很好。 以下作品
body = {
error: {
code: "Failed",
message: "A custom error message'."
}
};
httpStatus = 400;
context.res = {
status: httpStatus,
headers: {
'Content-Type': 'application/json'
},
body: body
};
我之前犯的錯誤是沒有正確設置 HTTP 狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.