Software /
code /
prosody
Changeset
11089:35d2260644d9
util.error: Extract error originator from stanza errors
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 26 Sep 2020 18:13:27 +0200 |
parents | 11088:1f84d0e4d0c4 |
children | 11090:33b6fbdcec88 |
files | spec/util_error_spec.lua util/error.lua |
diffstat | 2 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_error_spec.lua Sat Sep 26 18:12:18 2020 +0200 +++ b/spec/util_error_spec.lua Sat Sep 26 18:13:27 2020 +0200 @@ -48,12 +48,13 @@ it("works", function () local st = require "util.stanza"; local m = st.message({ type = "chat" }); - local e = st.error_reply(m, "modify", "bad-request"); + local e = st.error_reply(m, "modify", "bad-request", nil, "error.example"); 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); end); end);
--- a/util/error.lua Sat Sep 26 18:12:18 2020 +0200 +++ b/util/error.lua Sat Sep 26 18:13:27 2020 +0200 @@ -93,12 +93,17 @@ local function from_stanza(stanza, context) local error_type, condition, text = stanza:get_error(); + local error_tag = stanza:get_child("error"); + context = context or {}; + context.stanza = stanza; + context.by = error_tag.attr.by; return setmetatable({ type = error_type or "cancel"; condition = condition or "undefined-condition"; text = text; - context = context or { stanza = stanza }; + context = context; + }, error_mt); end