code: @Override
      public Resource getErrorpage(SlingHttpServletRequest request, int status) {
          Resource errorpage = null;
          ResourceResolver resolver = request.getResourceResolver();
  
          if (StringUtils.isNotBlank(errorpagesPath)) {
              if (errorpagesPath.startsWith("/")) {
                  // if the configured path is an absolute path use this path only
                  errorpage = resolver.getResource(errorpagesPath + "/" + status);
  
              } else {
                  String path = request.getRequestPathInfo().getResourcePath();
                  Resource resource = resolver.resolve(request, path);
  
                  // skip non existing resource paths in the requested path
                  while (ResourceUtil.isNonExistingResource(resource)) {
                      int lastSlash = path.lastIndexOf('/');
                      if (lastSlash > 0) {
                          path = path.substring(0, lastSlash);
                      } else {
                          path = "/";
                      }
                      resource = resolver.resolve(request, path);
                  }
  
                  // scan upwards for an appropriate error page
                  while (errorpage == null && resource != null) {
                      path = resource.getPath();
                      if ("/".equals(path)) {
                          path = "";
                      }
                      errorpage = resolver.getResource(path + "/" + errorpagesPath + "/" + status);
                      if (errorpage == null) {
                          resource = resource.getParent();
                      }
                  }
              }
          }
          if (errorpage == null && StringUtils.isNotBlank(defaultErrorpages)) {
              // use the default page if no custom error page found
              errorpage = resolver.getResource(defaultErrorpages + "/" + status);
          }
          return errorpage;
      }
docs: Determines the error page corresponding to the requested path.
  Is searching upwards beginning with the requested path for an error page
  using the path pattern: {requested path}/{errorpagesPath}/{status code}.
  If nothing found the pattern: {defaultErrorpages}/{status code} is used if existing.
  
  @return the error page found; <code>null</code> if no error page available