Changeset

11092:bd13aa89262d

util.error: Collect Application-Specific Conditions from stanza errors
author Kim Alvefur <zash@zash.se>
date Sat, 26 Sep 2020 18:15:49 +0200
parents 11091:4b4b5188492f
children 11093:ec14d4fce855
files spec/util_error_spec.lua util/error.lua
diffstat 2 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_error_spec.lua	Sat Sep 26 18:15:27 2020 +0200
+++ b/spec/util_error_spec.lua	Sat Sep 26 18:15:49 2020 +0200
@@ -48,13 +48,14 @@
 		it("works", function ()
 			local st = require "util.stanza";
 			local m = st.message({ type = "chat" });
-			local e = st.error_reply(m, "modify", "bad-request", nil, "error.example");
+			local e = st.error_reply(m, "modify", "bad-request", nil, "error.example"):tag("extra", { xmlns = "xmpp:example.test" });
 			local err = errors.from_stanza(e);
 			assert.truthy(errors.is_err(err));
 			assert.equal("modify", err.type);
 			assert.equal("bad-request", err.condition);
 			assert.equal(e, err.context.stanza);
 			assert.equal("error.example", err.context.by);
+			assert.not_nil(err.extra.tag);
 		end);
 	end);
 
--- a/util/error.lua	Sat Sep 26 18:15:27 2020 +0200
+++ b/util/error.lua	Sat Sep 26 18:15:49 2020 +0200
@@ -92,7 +92,7 @@
 end
 
 local function from_stanza(stanza, context)
-	local error_type, condition, text = stanza:get_error();
+	local error_type, condition, text, extra_tag = stanza:get_error();
 	local error_tag = stanza:get_child("error");
 	context = context or {};
 	context.stanza = stanza;
@@ -102,8 +102,9 @@
 		type = error_type or "cancel";
 		condition = condition or "undefined-condition";
 		text = text;
-		extra = condition == "gone" and {
+		extra = (extra_tag or condition == "gone") and {
 			uri = error_tag:get_child_text("gone", "urn:ietf:params:xml:ns:xmpp-stanzas");
+			tag = extra_tag;
 		} or nil;
 
 		context = context;