Repository: adobe-consulting-services/acs-aem-commons
Issue: Component,Page Error Handler - Not rendering html snippets in edit, preview mode when component throws error

Component error handler is not working as expected in AEM 6.0+service pack 1 and in some scenerios mentioned below impacting error handler as well. We are using latest released ACS commons package at https://github.com/Adobe-Consulting-Services/acs-aem-commons/releases/tag/acs-aem-commons-1.9.2 

Publisher Instance: Seems to render the html snippet and works fine.

Author instance (both classic and touch ui)
If there is a scripting or any exception thrown by the component. Check for the scenerios
- Not rending the respective html snippets configured in the edit, preview mode if the page has component throwing exception. 
- Working for publish view using http://localhost:4502/content/geometrixx/en.html?wcmmode=disabled
- Rending the respective html snippets configured in the edit, preview mode of the component error handler configuration if the page accessed doesn't not exits (404) and ACS commons error page handler is configured. 
- Above is working for publish view using http://localhost:4502/content/geometrixx/en.html?wcmmode=disabled
- In touch UI, if we access 404 page, it takes to http://localhost:4502/sites.html/content rather than custom 404 page i.e.  
  http://localhost:4502/editor.html/content/geometrixx/en.html -> in edit or preview mode takes to http://localhost:4502/sites.html/content


Changed files:
bundle/src/main/java/com/adobe/acs/commons/wcm/impl/ComponentErrorHandlerImpl.java

diff --git a/bundle/src/main/java/com/adobe/acs/commons/wcm/impl/ComponentErrorHandlerImpl.java b/bundle/src/main/java/com/adobe/acs/commons/wcm/impl/ComponentErrorHandlerImpl.java
index 4bd9c43fa..192b07ede 100644
--- a/bundle/src/main/java/com/adobe/acs/commons/wcm/impl/ComponentErrorHandlerImpl.java
+++ b/bundle/src/main/java/com/adobe/acs/commons/wcm/impl/ComponentErrorHandlerImpl.java
@@ -50,6 +50,7 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Map;
 
 @Component(
@@ -75,12 +76,15 @@ import java.util.Map;
 public class ComponentErrorHandlerImpl implements ComponentErrorHandler, Filter {
     private static final Logger log = LoggerFactory.getLogger(ComponentErrorHandlerImpl.class.getName());
 
-    // Magic number pushes filter lower in the chain so it executes after the
-    // OOTB WCM Debug Filter
-    static final int FILTER_ORDER = 1001;
+    // Magic number pushes filter lower in the chain so it executes after the OOTB WCM Debug Filter
+    // In AEM6 this must execute after WCM Developer Mode Filter which requires overriding the service.ranking via a
+    // sling:OsgiConfig node
+    static final int FILTER_ORDER = 1000000;
 
     static final String BLANK_HTML = "/dev/null";
-    static final String REQ_ATTR_PREVIOUSLY_PROCESSED = ComponentErrorHandlerImpl.class.getName() + "_previouslyProcessed";
+
+    static final String REQ_ATTR_PREVIOUSLY_PROCESSED =
+            ComponentErrorHandlerImpl.class.getName() + "_previouslyProcessed";
 
     @Reference
     private ResourceResolverFactory resourceResolverFactory;
@@ -316,7 +320,7 @@ public class ComponentErrorHandlerImpl implements ComponentErrorHandler, Filter
     }
 
     private boolean isFirstInChain(final SlingHttpServletRequest request) {
-        if(request.getAttribute(REQ_ATTR_PREVIOUSLY_PROCESSED) != null) {
+        if (request.getAttribute(REQ_ATTR_PREVIOUSLY_PROCESSED) != null) {
             return false;
         } else {
             request.setAttribute(REQ_ATTR_PREVIOUSLY_PROCESSED, true);
@@ -376,10 +380,7 @@ public class ComponentErrorHandlerImpl implements ComponentErrorHandler, Filter
         suppressedResourceTypes = PropertiesUtil.toStringArray(config.get(PROP_SUPPRESSED_RESOURCE_TYPES),
                 DEFAULT_SUPPRESSED_RESOURCE_TYPES);
 
-        log.info("Suppressed Resource Types:");
-        for (final String tmp : suppressedResourceTypes) {
-            log.info(" > {}", tmp);
-        }
+        log.info("Suppressed Resource Types: {}", Arrays.toString(suppressedResourceTypes));
     }
 
     @Override