How to replace Springs whitelabel error page with a blank page?

membersound :

On any exceptions, by default Spring routes to /error, which generates an error html page:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Oct 31 16:01:01 CET 2018
There was an unexpected error (type=Not Found, status=404)

Question: how can I instead show a blank page by default for a certain endpoint only?

There is a property server.error.whitelabel.enabled=false, but that disables the error handling entirely, so that the webservers default error page is shown (eg on tomcat a 404 tomcat error page).

That's not what I want. I'd just like to show a blank plain page. Or so to say: an empty response body. But how?

Because, for dev and test the whitelabel page is fine. But in production I'd like to hide any exception details entirely...

membersound :

I just discovered that this whitelabel error page is only shown inside a webbrowser requesting eg html content type.

If a spring rest webservice is accessed from a native client using just application/json, the error is translated to json automatically.

In case one would really want to show a blank page for webbrowsers, one could just override the BasicErrorController.errorHtml() bean method somehow.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=103044&siteId=1