azureazure-data-factory

How to get the innermost Error message of a Copy Activity Failure in Azure Data Factory


I'm aware that to get the usual error message, the expression to be used is : @activity('Copy Activity').Error.Message

But if the output of this expression looks like :

"Failure happened on 'Source' side. ErrorCode=RestCallFailedWithClientError,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Rest call failed with client error, status code 404 NotFound, please check your activity settings.\nResponse: {"error":{"code":"ErrorInvalidUser","message":"The requested user 'xxxx@yyyy.com' is invalid."}},Source=Microsoft.DataTransfer.ClientLibrary,'"

How do I capture the actual error : "The requested user 'xxxx@yyyy.com' is invalid." ?


Solution

  • I could use the below expression to the full error message to JSON and then get the required string.

    @json(substring(activity('Copy Activity').Error.Message, indexOf(activity('Copy Activity').Error.Message, '{'), subtract(add(lastIndexOf(activity('Copy Activity').Error.Message, '}'), 1), indexOf(activity('Copy Activity').Error.Message, '{')))).error.message
    

    In this expression:

    This will give you the specific error message "The requested user 'xxxx@yyyy.com' is invalid." from the JSON response.