title: Spring Data Rest exception handling - Return generic error response
body: <p>I want to know how can I handle internal server error type exceptions in Spring Data Rest such as JPA exceptions etc. due to a malformed request or a database crash. I did some research found that the better way to do this is by using @ControllerAdvice but couldn't find any working example of it. I looked at both these questions but they are still unanswered. </p>
  
  <p><a href="https://stackoverflow.com/questions/21150688/how-can-i-handle-exceptions-with-spring-data-rest-and-the-pagingandsortingreposi">How can I handle exceptions with Spring Data Rest and the PagingAndSortingRepository?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/29331770/global-exception-handling-for-rest-exposed-spring-data">global exception handling for rest exposed spring-data</a></p>
  
  <p>Can someone help me with a working example of how to use @ControllerAdvice and write a custom error response back to client whenever there is an exception. </p>