Skip to main content
Question

Title: Routing multiple HTTP error status codes without deep try_catch nesting

  • July 17, 2026
  • 0 replies
  • 8 views

 

Hi everyone,

This is a continuation of my previous post: Extracting dynamic JSON error messages from 4xx/5xx responses in a try_catch block.

Because the JSON payload is dropped when an HTTP action hits a 4xx or 5xx status code, we are discussing a workaround with our API team: having them provide highly specific, unique HTTP status codes for every single type of business error (e.g., 422 = “Error Message 1”, 423 = “Error Message 2”, 424 = “Error Message 3”). This would theoretically allow us to hardcode specific, static fallback messages for each error scenario.

The Challenge:
Agent Studio only allows one catch block per try. If the API returns 10 different status codes and we want to show 10 different static messages, we can't simply use a switch expression inside a single catch block because the HTTP status code of the failed action isn't exposed as a variable in the Data Bank.

Because of this, we are forced to write deeply nested try_catch blocks using the on_status_code filter to route each specific error. 

If we have 10 different error codes, this results in massive, hard-to-maintain YAML nesting.

My Question:
Is there a cleaner design pattern or workaround to route multiple status codes to different static messages without this deep nesting? How are others handling granular, status-code-based error routing in Compound Actions?