How to catch ERR_CONNECTION_REFUSED thrown by browser if server goes down?

This should work:

var socket = io('http://localhost');
socket.on('connect_error', function(err) {
  // notify user
});

The correct way to handle this, as of Socket 1.x, is to use the Manager object for a given socket. It throws a connect_error event that can be handled as shown:

socket.io.on('connect_error', function(err) {
  // handle server error here
  console.log('Error connecting to server');
});