Stacktrace of exceptions in Spring Rest responses
Spring provides an out of the box solution to handle all your custom exceptions from a single point. What you need is @ControllerAdvice
annotation in your exception controller:
@ControllerAdvice
public class GlobalDefaultExceptionHandler {
@ExceptionHandler(Exception.class)
public String exception(Exception e) {
return "error";
}
}
If you want to go deep into Springs @ExceptionHandler
at individual controller level or @ControllerAdvice
at global application level here is a good blog.