I have a pageable controller like following. I have used the filter which will give HttpServletResponse depending on the condition. And i want to show all user if only HttpServletResponse status code is 200. Or else i want to show custom message.
@GetMapping("/user/all")
@JsonView(Views.UserDetailView.class)
public ResponseEntity<?> getAllUsers(Pageable pageable,HttpServletResponse response) {
if (response.getStatus() == 200)
return ResponseEntity.ok(userRepository.findAll(pageable));
else
return new ResponseEntity<>(new JsonResponse("some error msg to show"),
HttpStatus.NOT_ACCEPTABLE);
}
sample of my user repository
public interface UserRepository extends JpaRepository<User, String> {
}
JsonResponse Dto
public class JsonResponse {
private String message;
private HttpStatus httpStatus;
//getter setter and constructor..
}
The problem with above implementation is that if the filter gives response code other than 200, then the response from the controller won't show custom error message. It only show the response code. Filter can produce various kinds of error codes such as 402 and 406. How can i show the custom error message?
ps: All other controllers works fine except the controller with Pageable object