Software /
code /
prosody
Changeset
11088:1f84d0e4d0c4
util.stanza: Extract Application-Specific Condition from errors
API change
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 26 Sep 2020 18:12:18 +0200 |
parents | 11087:cdd4684992f1 |
children | 11089:35d2260644d9 |
files | spec/util_stanza_spec.lua util/stanza.lua |
diffstat | 2 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua Sat Sep 26 19:00:17 2020 +0200 +++ b/spec/util_stanza_spec.lua Sat Sep 26 18:12:18 2020 +0200 @@ -276,6 +276,19 @@ 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"] = "<>";
--- a/util/stanza.lua Sat Sep 26 19:00:17 2020 +0200 +++ b/util/stanza.lua Sat Sep 26 18:12:18 2020 +0200 @@ -349,11 +349,11 @@ 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 @@ 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)