There is always an interchange of heartbeats between the nodes of a replica set. So, if the other nodes did not receive heartbeat from one nodes say 27001, then it means primary 27001 is down.
In this case its 27001, then there will be an election between 27002 and 27003. After the election, primary will be decided and your application should be still running.
For example: in vagrant m103:
start 3 node -replica set 27001, 27002 and 27003. Connect using:
mongo --host m103-repl/localhost:27001,localhost:27002,localhost:27003
Then shutdown 27001 node using kill command followed by
ps -ef | grep mongod
Then try to connect to the same replica set, you will see below message until the election is done.
Unable to reach primary for set m103-repl
Then you will automatically be connected to the new primary and thats how we ensure the connection in your application.