diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index 41486a15c28cd17bab4a063ee8367ea4c93cd1a6..934b2f88a729d7180a9c9fc890d37579393729a1 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -2075,7 +2075,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 		try:
 			who = helpers.get_full_jid_from_iq(prs)
 		except Exception:
-			if prs.getTag('error').getTag('jid-malformed'):
+			if prs.getTag('error') and prs.getTag('error').getTag('jid-malformed'):
 				# wrong jid, we probably tried to change our nick in a room to a non
 				# valid one
 				who = str(prs.getFrom())