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." ?
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:
indexOf(activity('Copy Activity').Error.Message, '{')
finds the starting position of the JSON part.
lastIndexOf(activity('Copy Activity').Error.Message, '}')
finds the ending position of the JSON part.
add(lastIndexOf(activity('Copy Activity').Error.Message, '}'), 1)
adds 1 to the ending position to include the closing brace.
subtract(add(lastIndexOf(activity('Copy Activity').Error.Message, '}'), 1), indexOf(activity('Copy Activity').Error.Message, '{'))
calculates the length of the JSON part.
substring()
extracts the JSON part from the error message.
json()
parses the extracted JSON part.
.error.message
accesses the innermost error message within the parsed JSON.
This will give you the specific error message "The requested user 'xxxx@yyyy.com' is invalid."
from the JSON response.