Caching pages that contains components with errors
Hi Masters!
We’ve been struggling with an issue for the last days, and we still don’t know how to handle it.
The problem is related to publish instances. The problem is when a HTL component contained in a page (and the Sling model underneath) throws an exception, the http response does not return a 500 error code (and the 500 error page), but a 200. The page shows all the components, except the component that has thrown the exception, which is shown partially.
The problem is, in publish instances, the page is cached, so next requests return the cached page, until the cache expires, no matter if the error is not occurring anymore in AEM.
This is related to components that make requests to external systems (Adobe Commerce, in our case), that sometimes return with errors. But we've also reproduced with the HelloWorld component provided by the Adobe archetype, just forcing an exception.
In this cases, we would like to prevent the page to be cached. How could we handle this situation? As far as I see, throwing an exception from the Java classes is not enough… Have you faced this problem before? Is this a supported use case?
Thank you very much!!