Forum Moderators: phranque

Message Too Old, No Replies

Why HTTP 501 error of type JSON presented to UI as text/html instead o

         

akatnet

3:58 am on May 29, 2016 (gmt 0)

5+ Year Member



I have front-end Angular running on Apache with back-end Spring REST API on Tomcat. Both Tomcat and Apache are fronted by load balancers running in AWS.

I wanted to throw 501 error in some error case and want that response to be presented as JSON to UI (Content-Type as "application/json"). This works fine in my local as expected with Angular is able to interpret the JSON response but when it comes to some common QA environment it fails because the 501 error presented to UI as text/html which Angular can't digest.

Difference between my local and QA is, Angular is running on node whereas QA uses Apache. Is the apache who is converting JSON response with 501 http code to html type?

I have setup ErrorDocument in httpd.conf only 500 and 400 errors, but Apache still intercepting 501 errors and throwing its own content in html format.

the response i get on my browser is below.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>501 Not Implemented</title>
</head><body>
<h1>Not Implemented</h1>
<p>GET to /test/customer/getCustomer not supported.<br />
</p>
</body></html>

lucy24

6:03 am on May 29, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have setup ErrorDocument in httpd.conf only 500 and 400 errors, but Apache still intercepting 501 errors and throwing its own content in html format.

In that case, isn't the server doing exactly what it's supposed to do? I'm not sure what you mean by "intercepting"; what were you expecting it to do in this situation?

The exact numerical error code doesn't matter, only that it's something without a declared ErrorDocument.

keyplyr

2:34 pm on May 29, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can't you just create a custom error page(s), set it up the way you want and add it to the config to be used instead of the server's default?

keyplyr

1:29 pm on May 30, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Explained in the ErrorDocument directive here: [httpd.apache.org...]