Add different handlers for the socket events 'error' and 'close'.