client: Deal with eg no-stream errors where no stanza is passed

Tue, 30 Sep 2014 12:18:28 +0200

author
Kim Alvefur <zash@zash.se>
date
Tue, 30 Sep 2014 12:18:28 +0200
changeset 364
69fc23b44819
parent 363
056ccefa6acf
child 365
48bf6993b4c4

client: Deal with eg no-stream errors where no stanza is passed

client.lua file | annotate | diff | comparison | revisions
--- a/client.lua	Tue Sep 30 12:16:33 2014 +0200
+++ b/client.lua	Tue Sep 30 12:18:28 2014 +0200
@@ -53,9 +53,13 @@
 
 function stream_callbacks.error(stream, e, stanza)
 	if stream:event(e, stanza) == nil then
-		local err = stanza:get_child(nil, "urn:ietf:params:xml:ns:xmpp-streams");
-		local text = stanza:get_child_text("text", "urn:ietf:params:xml:ns:xmpp-streams");
-		error(err.name..(text and ": "..text or ""));
+		if stanza then
+			local err = stanza:get_child(nil, "urn:ietf:params:xml:ns:xmpp-streams");
+			local text = stanza:get_child_text("text", "urn:ietf:params:xml:ns:xmpp-streams");
+			error(err.name..(text and ": "..text or ""));
+		else
+			error(stanza and stanza.name or e or "unknown-error");
+		end
 	end
 end
 

mercurial