--- a/spec/util_stanza_spec.lua Sat Sep 26 18:07:33 2020 +0200
+++ b/spec/util_stanza_spec.lua Sat Sep 26 18:09:10 2020 +0200
@@ -252,8 +252,20 @@
local gonner = st.error_reply(s, gone);
assert.are.equal("gone", gonner.tags[1].tags[1].name);
assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]);
+
+ local e = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened",
+ extra = {namespace="xmpp:example.test", condition="this-happened"} })
+ local r = st.error_reply(s, e);
+ assert.are.equal("xmpp:example.test", r.tags[1].tags[3].attr.xmlns);
+ assert.are.equal("this-happened", r.tags[1].tags[3].name);
+
+ local e2 = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened",
+ extra = {tag=st.stanza("that-happened", { xmlns = "xmpp:example.test", ["another-attribute"] = "here" })} })
+ local r2 = st.error_reply(s, e2);
+ assert.are.equal("xmpp:example.test", r2.tags[1].tags[3].attr.xmlns);
+ assert.are.equal("that-happened", r2.tags[1].tags[3].name);
+ assert.are.equal("here", r2.tags[1].tags[3].attr["another-attribute"]);
end);
-
end);
describe("should reject #invalid", function ()
--- a/util/stanza.lua Sat Sep 26 18:07:33 2020 +0200
+++ b/util/stanza.lua Sat Sep 26 18:09:10 2020 +0200
@@ -473,6 +473,11 @@
end
t:up();
if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end
+ if extra and is_stanza(extra.tag) then
+ t:add_child(extra.tag);
+ elseif extra and extra.namespace and extra.condition then
+ t:tag(extra.condition, { xmlns = extra.namespace }):up();
+ end
return t; -- stanza ready for adding app-specific errors
end