Let\'s say I have a repository like:
public interface MyRepository extends PagingAndSortingRepository {
@Query(\"....\")
Page<
You could use a global @ExceptionHandler with the @ControllerAdvice annotation. Basically, you define which Exception to handle with @ExceptionHandler within the class with @ControllerAdvice annotation, and then you implement what you want to do when that exception is thrown.
Like this:
@ControllerAdvice(basePackageClasses = RepositoryRestExceptionHandler.class)
public class GlobalExceptionHandler {
@ExceptionHandler({QueryException.class})
public ResponseEntity
See also: http://www.ekiras.com/2016/02/how-to-do-exception-handling-in-springboot-rest-application.html