0

I have front-end Angular running on Apache with back-end Spring REST API on Tomcat.

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?

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>
4
  • You are not using the correct HTTP code. Do not abuse codes like 501 for things they are not intended for. May 12, 2016 at 22:33
  • What HTTP error code should be return to client to indicate server error? May 15, 2016 at 18:32
  • That depends on the nature of the error. May 15, 2016 at 18:38
  • So, i am sending 500 for any custom exceptions from Java layer as a Json which i want my Angular layer digest it and display corresponding error on screen. But Apache interpreting all 5XX errors and displaying its default template error thought i don't have ErrorDocument configuration. This works perfect as expected without Apache :( May 15, 2016 at 19:43

1 Answer 1

0

Finally i was able to find what is causing Apache to replace all non 2XX responses with its own error document. All you need to do is, comment or set off ProxyErrorOverride. With this Apache will proxy pass error response as is from backend server to UI without loosing content, example it sends error response of type Json as it is without loosing headers.

ProxyErrorOverride Off

Hope this helps someone.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .