Kramer
Kramer

Reputation: 1088

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!

Upvotes: 0

Views: 183

Answers (1)

Vlad
Vlad

Reputation: 10780

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

  • Missing resource
  • No access to resource
  • Missing rendering servlet/script
  • Error in rendering servlet/script
  • Error in other invoked code (sling model, POJO, service)
  • ...

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.

Upvotes: 1

Related Questions