HTL/Sightly Exception Handling - to support a smoothly degeneration of a Page being on display in case of a single AEM/Sling Component fails
Hi,
I'm neither a Sling nor an AEM Genius. We want to migrate from CQ 5.6.1 with JSPs to AEM 6.2 with Sightly and Sling Models.
I have this wishful thinking, and maybe I'm too blind to see, but a central feature seems lacking to me in HTL, which is the smooth degeneration of a Page if one of the Components (either being on a parsys or hard coded in the templates) is running wild (during initialization, or during the rendering of actual content - using either the Use or Sling Models API, of which the content typically gets cached for a certain amount time in the Dispatcher Cache - at least for us).
I spent quite some time searching on the AEM forum and the internet for a suitable solution - without results, so I decided to ask this question as a "last resort".
Typical to an enterprise scenario combing JCR with none JCR Backends, it is likely to happen sooner or later for external content integration (REST-, SOAP-API, DB Access), that it fails upon actual data retrieval, due to some unavailability issues, thus provoking an Exception in the respective AEM Component for display as a net effect.
Side notes:
I assume that the respective Components behave more or less like "portlets", which means they are pretty independent of the rest of the content on the page.
A Good practice for us (and in general?) is to propagate an Exception you cannot handle (thus being a Runtime Exception ...) to the upper layers where they are treated as a cross cutting concern... In our case the UI Layer (aka Sling/AEM Components/the Sling Scripting Framework with logic backed by Java Classes).
I looked in the Sling Documentation, which seemed promising at first, however, the Exception Handling using https://sling.apache.org/documentation/the-sling-engine/errorhandling.html - Uncaught Throwables - doesn't seem to be WCMMode agnostic:
If the WCMMode is "edit" it comes close to what we want (instead of a Stacktrace, we would like to let an author define either a general error message or an empty string for production - i.e. not rending the component in the end on failure).
If the WCMMode is "disabled" as on a Publisher, the whole page is replaced by the content provided by the Error Handler being invoked, which is not acceptable for the client (all or nothing isn't an option).
I looked through the WCM Use, Sling Models and SlingScript and -Resolver API, however, I feel like they all run short in supporting what we actually want...
To have an own implementation of a parsys with special Exception Handling seems to be only a part of the Solution, as scripts to be included in the HTL can be hard coded - hence it doesn't provide for a general solution.
To put it the other way round, I look for a clever replacement in HTL for the JSP javax.servlet.jsp.tagext.TryCatchFinally that we used to harness by supplying an own JSP Tag Library with Backing Bean Support (~ Sling Models) in CQ 5.6.1.
Actually, I wonder why google searches for "Sling Models Exception Handling" or "HTL/Sightly Exception Handling" don't show any useful/relevant results ... :-(
Any clues that go into the direction of gentle degeneration in the context of HTL/Sightly Component Failures are highly appreciated :-)
Thank you very much in advance.
Cheers,
Markus