AEM always returns 200 status code. | Community
Skip to main content
janellic4
Level 2
August 29, 2019
Solved

AEM always returns 200 status code.

  • August 29, 2019
  • 34 replies
  • 25904 views

Upon requesting non-existent pages, both aem author and publish instances return blank page with 200 status code. The default 404 error page is not showing.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by leoberliant

Do you have any custom filters that can possibly massage the response? You might want to stop your custom bundles in OSGi and use /system/console/requests to track recent requests.

34 replies

Adobe Employee
August 29, 2019
janellic4
janellic4Author
Level 2
August 29, 2019

Thank you for your response. I tried the custom error handler, but the results are the same. The aem just returns blank page with 200 status code even if the request url is invalid. Not sure what is wrong?

janellic4
janellic4Author
Level 2
August 29, 2019

I never got the default 404 not found page working in my local author and publish instances. If the request url is invalid, the response would be a black page with 0 content length, while the HTTP status code is 200. Anyone met with the same problem?

janellic4
janellic4Author
Level 2
August 29, 2019

Sorry, a typo. The response is blank page.

Gaurav-Behl
Level 10
August 29, 2019

Do you see 404.html or 404.jsp in your AEM instance under  /apps/sling/servlet/errorhandler/?

http://localhost:4502/crx/de/index.jsp#/apps/sling/servlet/errorhandler/404.html

janellic4
janellic4Author
Level 2
August 29, 2019

yes, I created a 404.html and ResponseStatus.java under /apps/sling/servlet/errorhandler

In the 404.html, the code is as:

<sly data-sly-use.responseStatus="apps.sling.servlet.errorhandler.ResponseStatus">

    <sly data-sly-resource="/content/myproject/en/page-not-found.html"></sly>

</sly>

The code in ResponseStatus.java is:

package apps.sling.servlet.errorhandler;

import com.adobe.cq.sightly.WCMUsePojo;

public class ResponseStatus extends WCMUsePojo { 

    @Override

    public void activate() throws Exception {

        getResponse().setStatus(404);

    }

}

janellic4
janellic4Author
Level 2
August 29, 2019

"/content/myproject/en/page-not-found.html" is a custom 404 error page.

Adobe Employee
August 29, 2019

That does not look like a deafult behavior. AEM should give you a 404 for non existing nodes:

jbrar-macOS:~ jbrar$ curl -u admin:admin http://localhost:6333/content/geometrixx-outdoors/en/men/pants/fulani-noma -I

HTTP/1.1 404 Not Found

Date: Thu, 29 Aug 2019 21:08:49 GMT

X-Content-Type-Options: nosniff

Set-Cookie: cq-authoring-mode=TOUCH;Path=/;Expires=Thu, 05-Sep-2019 21:08:49 GMT;Max-Age=604800

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Content-Type: text/html;charset=utf-8

Transfer-Encoding: chunked

Can you check if you get the 404 response when running a curl command? If yes, the error handler implementation is wrong

janellic4
janellic4Author
Level 2
August 29, 2019

I am not able to get the 404 response when running a curl command to request a non-existent page. Nothing shows up in the terminal, however, I am able to get the correct page for a valid url using curl.

For example, requesting http://localhost:4503/content/myproject/en/search-results shows the html page content, however, requesting http://localhost:4503/content/myproject/en/no-page did not get any response.

janellic4
janellic4Author
Level 2
August 29, 2019

I never get a 404 response from the AEM, either in Author or in Publisher. That is very strange.