Disconnect if an error is thrown during the connection.