Azure-docs: Error Handling help

Created on 2 Dec 2019  Â·  8Comments  Â·  Source: MicrosoftDocs/azure-docs

I struggled to invoke a failure to ADF from the webhook so below is the powershell I used to help others:
Param(
[object]$WebhookData
)
if ($WebhookData){
$parameters = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
if($parameters.callBackUri) {$callBackUri = $parameters.callBackUri}
}

$jsonRequest = [ordered]@{
output= @{
restoreStatus = "Failed"
}
error = @{
ErrorCode = "RestoreError"
Message = "Restoring the Database failed"
}
statusCode = "500"
}

    $jsonBody = $jsonRequest | ConvertTo-Json -Depth 10

    $jsonBody

    $headers = @{
        "Content-Type"="application/json"
    }

    Invoke-WebRequest -Uri $callBackUri -UseBasicParsing -Method POST -Body $jsonBody -Header $headers

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 assigned-to-author data-factorsvc doc-enhancement doc-idea triaged

Most helpful comment

If this code can be contributed in some way as an example I think it could help users a lot more.

Context - Calling a Webhook from an ADF pipeline to perform a Restore of an Azure SQL Database, if it fails I want the ADF pipeline to fail also and not carry on performing any more activities.
This section is for the start of your powershell script:

Param(
[object]$WebhookData
)
if ($WebhookData){
$parameters = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
if($parameters.callBackUri) {$callBackUri = $parameters.callBackUri}
}

You need the parameter to receive the Webhookdata from ADF and then you can get the callbackuri so you can send a web request back to say whether it succeeds or fails.

If it succeeds then you can simply put:
Invoke-WebRequest -Uri $callBackUri -UseBasicParsing -Method POST

If it fails then in the catch I have put the following to fail the ADF webhok activity:

$jsonRequest = [ordered]@{
                                output= @{
                                    restoreStatus = "Failed"
                                }
                                error = @{
                                    ErrorCode = "RestoreError"
                                    Message = "Restoring the Database failed"
                                }
                                statusCode = "500"
                            }


        $jsonBody = $jsonRequest | ConvertTo-Json -Depth 10

        $jsonBody

        $headers = @{
            "Content-Type"="application/json"
        }

        Invoke-WebRequest -Uri $callBackUri -UseBasicParsing -Method POST -Body $jsonBody -Header $headers

Hope this helps. If you need more information let me know.

All 8 comments

Thanks for the feedback and bringing this to our notice . At this time we are reviewing the feedback and will update the document as appropriate .

Hello @bigdaveydave . Could you please clarify the ask?

Is there a problem to be solved, or is this code you wish to contribute to the documentation?

If this is code you wish to contribute, could you please give more context of when to use it, and explain in detail the expected behavior?

If this code can be contributed in some way as an example I think it could help users a lot more.

Context - Calling a Webhook from an ADF pipeline to perform a Restore of an Azure SQL Database, if it fails I want the ADF pipeline to fail also and not carry on performing any more activities.
This section is for the start of your powershell script:

Param(
[object]$WebhookData
)
if ($WebhookData){
$parameters = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
if($parameters.callBackUri) {$callBackUri = $parameters.callBackUri}
}

You need the parameter to receive the Webhookdata from ADF and then you can get the callbackuri so you can send a web request back to say whether it succeeds or fails.

If it succeeds then you can simply put:
Invoke-WebRequest -Uri $callBackUri -UseBasicParsing -Method POST

If it fails then in the catch I have put the following to fail the ADF webhok activity:

$jsonRequest = [ordered]@{
                                output= @{
                                    restoreStatus = "Failed"
                                }
                                error = @{
                                    ErrorCode = "RestoreError"
                                    Message = "Restoring the Database failed"
                                }
                                statusCode = "500"
                            }


        $jsonBody = $jsonRequest | ConvertTo-Json -Depth 10

        $jsonBody

        $headers = @{
            "Content-Type"="application/json"
        }

        Invoke-WebRequest -Uri $callBackUri -UseBasicParsing -Method POST -Body $jsonBody -Header $headers

Hope this helps. If you need more information let me know.

Thank you very much for the clarification @bigdaveydave . A webhook tutorial would be a beneficial addition to our docs. Would you be interested in helping create one?

@djpmsft This contribution could be helpful in illustrating how to implement the "Report status on callback" option of Webhook. Do you think I should insert this into the docs, or should I leave as is?

This implementation is specific to PowerShell. If I read this in the docs, I would ask "how do I get URL for my PowerShell".
In my opinion, a full tutorial / how-to would be a beneficial addition to the docs. To match the standards of the other tutorials, the following points would be covered:

  • Create Data Factory
  • Create Compute service (or whatever hosts the endpoint)
  • Get a URL
  • Make pipeline and WebHook activity
  • Write script to respond to WebHook
  • Pipeline response to callback

I just wanted to add that I was struggling with callbacks as it is currently documented here (and elsewhere) and it was only when i read this open issue that I managed to get a callback working with a body by following @bigdaveydave's example.

This is really helpful! I spent 2 hours to find an example of how to fail a runbook webhook activity. And I got it here. Great, thanks very much!

assign chez-charlie

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrdfuse picture mrdfuse  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments

Ponant picture Ponant  Â·  3Comments

monteledwards picture monteledwards  Â·  3Comments

jebeld17 picture jebeld17  Â·  3Comments