# HG changeset patch # User Kim Alvefur # Date 1601136949 -7200 # Node ID bd13aa89262d141c47ecc3e4bf1bb6d5fb6d040f # Parent 4b4b5188492f9438ce3a280cb73045491e82efa6 util.error: Collect Application-Specific Conditions from stanza errors diff -r 4b4b5188492f -r bd13aa89262d spec/util_error_spec.lua --- 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); diff -r 4b4b5188492f -r bd13aa89262d util/error.lua --- 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;