Optimizing Azure Logic Apps for Better Exception Handling

Author: Jayakumar SrinivasanDate: 02-Dec-2024

Overview of the Problem

Introduction

Developing complex logic apps that interact with multiple external API, databases, FTP servers, etc., often presents significant challenges in exception handling. This complexity is exacerbated when processing within loops. Such logic apps are notoriously difficult to troubleshoot, requiring a detailed examination of the run history to identify failures. Additionally, during my reviews, I have observed that these logic apps frequently send generic error messages with irrelevant status codes when exceptions occur.

A sample complexity

In my reviews, I frequently encounter logic apps performing following tasks: retrieve all files from an SFTP folder, obtain a token from an Authentication API, call an external system with the token, parse the data of each file in a loop, send the parsed data to another API, make database entries, move the file to different SFTP folders based on processing success or failure, and exit the logic app with a response or Terminate action. The developers often declare very few scopes to manage exceptions, resulting in generic “Internal Server Error” messages. Consequently, the development team must examine the run history to pinpoint the failure.


Complexity Root Cause

Analysis

When developing complex logic apps, it is crucial to handle exceptions at critical points, such as API calls, file processing, database interactions, and JSON parsing from external systems. Common issues identified in my reviews include:

  • Unrecognized system complexity at the start of development
  • Inadequate complexity assessment during design
  • Insufficient development time
  • Excessive use of connectors
  • Uncertainty in managing exceptions within control loops

Proposed Solution

Solution Description

The proposed solution leverages the default capabilities of logic apps to avoid complexity. It involves using two variables: a string variable to capture error messages from various actions and a Boolean variable to indicate exceptions in the workflow. The key aspect of this solution is defining scopes for every complex external or built-in connector. Consider creating separate logic apps to overcome action nesting depth limitations.

By defining scopes at each connector allows for capturing exceptions specific to an operation. The string variable will append exceptions from various connectors, enabling the storing precise error messages related to specific operations. The Boolean variable flag will be set false denoting exceptions in the workflow. The string variable is particularly useful for control connectors, as it helps identify failed items within loops by summarizing the failures (e.g., out of 5 items, 1 failed) with appropriate exception messages.

Key Considerations Before Development

  • Clear requirements for development
  • Involvement of built-in and custom connectors
  • Possibility of separating workflows into child logic apps
  • Fixed request and response schemas for external systems

Benefits

Following will be the benefits of the proposed solution

  • Precise identification of exceptions
  • Context-specific exception messages
  • Summary of exceptions when using control (loop) connectors
  • Decision-making facilitation at the end of the workflow to determine logic app success or failure
  • Simplified troubleshooting

References