skip to Main Content

I have a logic app, and there are 2 actions related to question.

pic1

How can i get specific error message from 1st action and use it in second (in expression)?
I noticed that there are many scenarios possible.

  1. Internal Server Error (500) with no message
  2. 4xx status code (can be with or without message)
  3. Action timed out and has no output (portal still says BadRequest, 3rd pic)

pic 2
pic 3

2

Answers


  1. This is a flow that demonstrates what to do …

    Flow

    A lot of it is semantics to throw an error but the most important section is at the bottom.

    Basically, within the Scope section, I’m setting a variable that divides an amount by 0 which, as you’d expect, throws an error.

    The Initialize Error (set as an Array) step at the bottom reads the result information that comes out of the Scope execution. You can do this by using the result() expression.

    So in completeness, the expression within that step is …

    result('Scope')
    

    https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#result

    … but you also need to make sure you set the behaviour of the Initialize Error step to actually fire after an error from that which occurs within the Scope

    https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-exception-handling?tabs=consumption#change-run-after-behavior-in-the-designer

    Configure After

    … and this is the result of that execution …

    Error

    {
        "variables": [
            {
                "name": "Error",
                "type": "Array",
                "value": [
                    {
                        "name": "Set_Result",
                        "startTime": "2023-03-23T21:10:37.2196056Z",
                        "endTime": "2023-03-23T21:10:37.2664847Z",
                        "trackingId": "aae322b9-1fe5-4d64-86fe-aee282dbfad9",
                        "clientTrackingId": "08585220010487995760029287748CU07",
                        "code": "BadRequest",
                        "status": "Failed",
                        "error": {
                            "code": "InvalidTemplate",
                            "message": "Unable to process template language expressions in action 'Set_Result' inputs at line '0' and column '0': 'Attempt to divide an integral or decimal value by zero in function 'div'.'."
                        }
                    }
                ]
            }
        ]
    }
    
    Login or Signup to reply.
  2. if you have more "levels" in your logic app, for example

    a scope -> loop -> condition

    then you need to union() the result() from each "level":

    @union(result('scope'),result('for-each'), result('condition'))
    

    then you can filter thru this array to find what you are looking for, I use it to find Failed runs and its outputs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search