I am try to do something like
Optional<Order> orderDetails = orderRepository.findById(orderId);
if (orderDetails.isEmpty())
throw new OrderNotFoundException("Order not found!");
Optional<User> UserDetails = userRepository.findById(userId);
if (UserDetails.isEmpty())
throw new UserNotFoundException("User not found!");
List<OrderItem> ItemDetailsList = orderItemRepository.findByOrderIdOrderByItemIdAsc(orderId);
Where I want to call these three Services methods together in a non-blocking way, but I want to throw error if any one of those call fails and dont proceed furthur. If all of the above works, then execute the later logic.
I am thinking of using allOff() then after that use get on the Futures and do the above logic of throwing error when the Optional is empty?
Is there better way of doing it ? i.e if one of them fails and others are still running, throw error and abort the other running tasks.