1
votes

I have a simple logic app running an Azure Function on a recurrence trigger (every day). I want to send the IT department an email if there is a problem running the Function. Here's my Logic App setup:

enter image description here

However, whenever there is an error (for exemple, the azure function returns an HTTP code 500, like so:)

return req.CreateResponse(HttpStatusCode.InternalServerError, new
        {
            error = $"{errorMessage}. {ex.Message}"
        });

the Logic App flow just stops before I can check the status code an react to it:

enter image description here

So my question is: is there a way to handle an Azure Function error response code?

2

2 Answers

5
votes

The reason for this failure is that by default the Logic App Condition is executed only on the success of the previous step.

You can override this behavior by updating the "runAfter" condition to include "Failed" state.

Go to the code view and add update your definition of error condition in json to have

                "runAfter": {
                "HTTP": [
                    "Failed",
                    "Succeeded"
                ]
1
votes

With this week's Logic Apps update, you can specify "Run after" condition right within the designer and don't need to switch to code view. In your case, simply move "Gmail - send email" action outside of the condition, right after the Function action. Then click on "..." on the title bar of the "Gmail - send email" action, you should see an option called "Configure run after". Check "has failed" and the email action will be executed if the Function call has failed.