java - ResponseEntityExceptionHandler does not send an error code to the client despite @ResponseStatus annotation -


i want prevent spring sending complete stacktrace of runtimexceptions front end. did this:

@controlleradvice public class resterrorhandler extends responseentityexceptionhandler {      @exceptionhandler(exception.class)     @responsestatus(value = httpstatus.internal_server_error)     @override     protected responseentity<object> handleexceptioninternal(exception e, object body,                 httpheaders headers, httpstatus status, webrequest request) {         logger.error("error happened while executing controller.", e);         return null;     } } 

my objective send error code , nothing else front end. above method returns status 200 ok front end. should returned instead of null ?

with @responsestatus, if providing value, httpservletresponse.setstatus(int) used:

this method used set return status code when there no error (for example, sc_ok or sc_moved_temporarily status codes).

if method used set error code, container's error page mechanism not triggered. if there error , caller wishes invoke error page defined in web application, senderror(int, java.lang.string) must used instead.

if providing reason well, httpservletresponse.senderror(int, string) used instead.

@controlleradvice public class resterrorhandler {     @responsestatus(value = httpstatus.internal_server_error, reason = "internal_server_error")     @exceptionhandler(exception.class)     public void handleconflict(exception e) {         // log me     } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -