I am trying to capture the error and Fail the webhook activity if my runbook is failed.
I have tried with callback URL but it is not working.
Also webhook activity is getting successful even the runbook got failed.
Runbook code is written in PowerShell.
ErrorMessage is capturing the error from catch statement.
code
callbackurl
if ($ErrorMessage) {
$OutputJson = @"
{
"output": { "message": "$ErrorMessage" },
"statusCode": 500,
"error": {
"ErrorCode": "Error",
"Message": "$ErrorMessage"
}
}
"@
}
if ($callBackUri) {
Invoke-WebRequest -Uri $callbackuri -UseBasicParsing -Method POST -ContentType "application/json" -Body $OutputJson
}