title: Why ErrorHandler component is not registering properly in SlingMainServlet?
body: <p>I have a simple component for my own ErrorHandler implementation:</p>
  
  <pre><code>@Component(immediate = true)
  @Service
  @Properties(
          @Property(name = "service.ranking", intValue = 1)
  )
  public class MyErrorHandler implements ErrorHandler {
  
      @Override
      public void handleError(int status, String message, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
          handleError(status, request, response);
      }
  
      @Override
      public void handleError(Throwable throwable, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
          handleError(505, request, response);
      }
  
      private void handleError(int status, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
          if (status != 200) {
              try {
                  request.getRequestDispatcher("/etc/errors/" + status + ".html").forward(request, response);
              } catch (ServletException e) {
                  throw new IllegalStateException("No error pages");
              }
      }
  }
  </code></pre>
  
  <p>If I deploy the component to Sling, nothings happen until restart of whole Sling. It's not a good solution I  guess.</p>
  
  <h3>Short explanation about using ErrorHandler instead of handling scripts (for those who would ask 'why you didn't use overloaded script)</h3>
  
  <ol>
  <li>Writing own Servlet is too complex for that easy behaviour</li>
  <li>Scripts are less maintainable than java code (in sling).</li>
  </ol>