Conditions for API results that lead to an error

Imagine an API result leads to an error like a 404. How would we check for that and output some alternative content when that occurs? Unless I’m missing something this isn’t possible at the moment.

To give an example, I’m grabbing random images from an API and some of those images may lead to a 404. The API result is technically not empty since the image URL is returned, it’s just that it leads to a 404 when the image no longer exists. How can we account for situations like this?

So start with the API Tester. Inside the Error element you can use {{dc:looper:field key="info.http_code"}} which is the status code. From there you can display certain content based on status code using that Dynamic content. Everything in that Info section of API Tester is a key you can use through looper:field. A little more notes here. Let me know if this helps!

So debug must be turned on permanently for that to work?

Yes to use the request info. It’s not a great name for it, you can look it at more of an “Advanced” mode. I’ll probably change the name at some point. It’s fine to have on a production environment.