I have implemented a RestControllerAdvice for handling exception in Spring Boot-Tomcat Web application as shown below :
@RestControllerAdvice
public class ExceptionHandlerRest{
private Logger logger=LoggerFactory.getLogger(getClass());
@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleException(Exception ex){
logger.error("System Error", ex);
SimpleResponse=new SimpleResponse(ex.getMessage(),"Error code 001"));
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
So whenever a web request results into exception i am expecting above handler to return status 500 and a json having content : "{"technicalMessage" : "NullPointerException","userMessage":"Error Code 001"}
However,instead of that a html error page is coming printing entire stack trace as shown below :
the SimpleResponse has below definition :
public class SimpleResponse{
String technicalMessage,userMessage;
//public getters and setters
}
I have put debug point and observed that code flow does reach properly to return statement of handleException of RestControllerAdvice. I think some how tomcat is ignoring my response and showing exception stack trace. How can i make my application return error message in a json ?
BaseScreeningException? Is this being thrown within your exception handler? - g00glen00b