aemslingsightlyhtl

How do I detect that a Sling component failed to render and take appropriate action?


I am running AEM 6.3 and have an application built using HTL, Java, etc. I have a component included as a resource as follows:

<div data-sly-resource="${ 'resource-name' @ resourceType='path/to/resource'}"></div>

In some cases, that resource is failing to load and no HTML is being rendered. How can I detected that failure and take action?

Preferably, I'd like to return the response as normal and set an HTTP header.

Thanks for your help!


Solution

  • A resource failing to render can happen due to various reasons:

    Even if you manage to detect some of these failures in the middle of processing, setting a response header then might be too late as part of the response could already be committed/flushed.

    One solution that might work is to setup a filter to handle resource rendering errors. You could also buffer the response to make sure you begin sending only after all processing is completed.