diff options
author | Kim Alvefur <zash@zash.se> | 2020-09-26 17:26:31 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-09-26 17:26:31 +0200 |
commit | 2f0b85ce29a6b4eaa210a60a5d04610f0401379d (patch) | |
tree | 2721a67a00a2adf70129199dd6e42affac3d452d | |
parent | d9e80064b5e57d3055a4d0e93f732e14c4c11a11 (diff) | |
download | prosody-2f0b85ce29a6b4eaa210a60a5d04610f0401379d.tar.gz prosody-2f0b85ce29a6b4eaa210a60a5d04610f0401379d.zip |
util.stanza: Support getting 'by' from util.error object
-rw-r--r-- | spec/util_stanza_spec.lua | 3 | ||||
-rw-r--r-- | util/stanza.lua | 3 |
2 files changed, 5 insertions, 1 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index efe3e47e..ec392611 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -234,7 +234,7 @@ describe("util.stanza", function() it("should accept util.error objects", function () local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); - local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork" }); + local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork", extra = { by = "this.test" } }); local r = st.error_reply(s, e); assert.are.equal(r.name, s.name); @@ -246,6 +246,7 @@ describe("util.stanza", function() assert.are.equal(r.tags[1].attr.type, e.type); assert.are.equal(r.tags[1].tags[1].name, e.condition); assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); + assert.are.equal("this.test", r.tags[1].attr.by); end); end); diff --git a/util/stanza.lua b/util/stanza.lua index 7d45d444..3c415f20 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -456,6 +456,9 @@ local function error_reply(orig, error_type, condition, error_message, error_by) local t = reply(orig); t.attr.type = "error"; if type(error_type) == "table" then -- an util.error or similar object + if type(error_type.extra) == "table" then + if type(error_type.extra.by) == "string" then error_by = error_type.extra.by; end + end error_type, condition, error_message = error_type.type, error_type.condition, error_type.text; end if t.attr.from == error_by then |