diff options
author | Kim Alvefur <zash@zash.se> | 2020-09-26 18:15:49 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-09-26 18:15:49 +0200 |
commit | a51d5912465d8129ab062572d1f2e2bdddf967e6 (patch) | |
tree | cc9986d335559d38966ce073f7b6e3ca32848b2b | |
parent | 3c7cbd0e2cbf471addcc332f2a8ba5cd635ae845 (diff) | |
download | prosody-a51d5912465d8129ab062572d1f2e2bdddf967e6.tar.gz prosody-a51d5912465d8129ab062572d1f2e2bdddf967e6.zip |
util.error: Collect Application-Specific Conditions from stanza errors
-rw-r--r-- | spec/util_error_spec.lua | 3 | ||||
-rw-r--r-- | util/error.lua | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index 9cb1c57b..bb85d303 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -48,13 +48,14 @@ describe("util.error", function () 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); diff --git a/util/error.lua b/util/error.lua index c0b87d86..92567248 100644 --- a/util/error.lua +++ b/util/error.lua @@ -92,7 +92,7 @@ local function coerce(ok, err, ...) 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 @@ local function from_stanza(stanza, context) 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; |