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!!
Solved! Go to Solution.
Views
Replies
Total Likes
I think Sling Dynamic Include is the perfect solution for you if I have understood your components behavior. Sling dynamic include helps you to cache/not cache a specific component. And this is a perfect match for the components which need to show response from other systems like you are calling an api. Check out this link here for more https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/development/set-up-sling...
This is how I have it on our end
Hi @Julio_Baixauli Over here you are waiting for the response and then trying to serve the content. And meanwhile there is a request time out and you must have handled the execption and that's the reason for the response code as 200.
IMO, when you need to cache the http response from the cache, you should write a Scheduler via a Sling Job and store the data within the AEM. This way your content will be served faster during the first load and going forward as well and the load on the server will also be reduced.
Over here as you will be syncing the data from commerce to AEM author. So, once the data is there in the AEM author instance, verify it by handler/listener/workflow using any of the flag that would be set while storing the data and replicate it to the other publish instances as well.
This way it will be fully automated as well.
Hope this helps!
Thanks
Hi Julio,
Once you get an exception from commerce service, set response status to 500 for this request.
Then tell Dispatcher to not cache 500 and ask Dispatcher to do the logic you need Dispatcher to do.
Regards,
Peter
@Julio_Baixauli : Component errors specifically in sling model could be associated with your component dialog values. Therefore you should be seeing the same error on author instance as well and page should ideally not be replicated.
Once the error is corrected by authoring dialog field values, page can be published and that should clear the cache for your page on dispatcher and users would start to see updated page without error.
Please let me know if I have assumed something and this is not the case for your error.
thanks.
@Julio_Baixauli Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
I think Sling Dynamic Include is the perfect solution for you if I have understood your components behavior. Sling dynamic include helps you to cache/not cache a specific component. And this is a perfect match for the components which need to show response from other systems like you are calling an api. Check out this link here for more https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/development/set-up-sling...
This is how I have it on our end
Views
Likes
Replies
Views
Likes
Replies