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

AEM always returns 200 status code.

  • August 29, 2019
  • 34 replies
  • 25894 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

cal-netsolution
New Participant
August 30, 2019

Can you try creating the error pages using ACS commons error page handler.

https://adobe-consulting-services.github.io/acs-aem-commons/features/error-handler/index.html

In this article there is step by step process to create custom error pages and also settings in dispatcher.

Error Page Handler

https://adobe-consulting-services.github.io

Best,

Cal

Himanshu_Singhal
New Participant
August 30, 2019

That could be due to Response buffer size as well that you always get 200 instead of any other error code. If the rendered response buffer is more than defined one, then server send response back to browser in chunks and once it's sends a part of response, no matter if page works or not, if always return 200.

You can try increasing the buffer size by going into configuration:

Apache Felix Jetty Based Http Service

"Response Buffer Size"

Increase the size and if page throws error then it should get displayed as well.

Umesh_Sondhi
New Participant
August 30, 2019

hi janellic4 ,

This link can help you understand why you are getting 200 and not 404 response .

https://experiencemanaged.com/posts/efficient-error-handling-with-aem-dispatcher-and-apache-web-server.html

Thanks 

janellic4
janellic4Author
New Participant
August 29, 2019

Update for the curl command: I get 200 status for both the valid and invalid url request.

Response for requesting the valid url : http://localhost:4503/content/myproject/en/search-results.html

HTTP/1.1 200 OK

Date: Thu, 29 Aug 2019 21:45:38 GMT

X-Content-Type-Options: nosniff

Set-Cookie: cq-authoring-mode=TOUCH;Path=/;Expires=Thu, 05-Sep-2019 21:45:38 GMT

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

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

Transfer-Encoding: chunked

Response for the invalid url: http://localhost:4503/content/myproject/en/no-page.html

HTTP/1.1 200 OK

Date: Thu, 29 Aug 2019 21:46:15 GMT

X-Content-Type-Options: nosniff

Set-Cookie: cq-authoring-mode=TOUCH;Path=/;Expires=Thu, 05-Sep-2019 21:46:15 GMT

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

Content-Length: 0

janellic4
janellic4Author
New Participant
August 29, 2019

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

janellic4
janellic4Author
New Participant
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.

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
New Participant
August 29, 2019

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

janellic4
janellic4Author
New Participant
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);

    }

}

Gaurav-Behl
New Participant
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