aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/util_stanza_spec.lua13
-rw-r--r--util/stanza.lua14
2 files changed, 21 insertions, 6 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index a363086c..535f783b 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -276,6 +276,19 @@ describe("util.stanza", function()
end);
end);
+ describe("#get_error()", function ()
+ describe("basics", function ()
+ local s = st.message();
+ local e = st.error_reply(s, "cancel", "not-acceptable", "UNACCEPTABLE!!!! ONE MILLION YEARS DUNGEON!")
+ :tag("dungeon", { xmlns = "urn:uuid:c9026187-5b05-4e70-b265-c3b6338a7d0f", period="1000000years"});
+ local typ, cond, text, extra = e:get_error();
+ assert.equal("cancel", typ);
+ assert.equal("not-acceptable", cond);
+ assert.equal("UNACCEPTABLE!!!! ONE MILLION YEARS DUNGEON!", text);
+ assert.not_nil(extra)
+ end)
+ end)
+
describe("should reject #invalid", function ()
local invalid_names = {
["empty string"] = "", ["characters"] = "<>";
diff --git a/util/stanza.lua b/util/stanza.lua
index 9bcf3747..94815346 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -349,11 +349,11 @@ function stanza_mt.get_text(t)
end
function stanza_mt.get_error(stanza)
- local error_type, condition, text;
+ local error_type, condition, text, extra_tag;
local error_tag = stanza:get_child("error");
if not error_tag then
- return nil, nil, nil;
+ return nil, nil, nil, nil;
end
error_type = error_tag.attr.type;
@@ -364,12 +364,14 @@ function stanza_mt.get_error(stanza)
elseif not condition then
condition = child.name;
end
- if condition and text then
- break;
- end
+ else
+ extra_tag = child;
+ end
+ if condition and text and extra_tag then
+ break;
end
end
- return error_type, condition or "undefined-condition", text;
+ return error_type, condition or "undefined-condition", text, extra_tag;
end
local function preserialize(stanza)