# HG changeset patch # User Kim Alvefur # Date 1601136807 -7200 # Node ID 35d2260644d90ebeae1ac06fcbcedbec7acd7fc7 # Parent 1f84d0e4d0c409c2695eebb8fea39e6413ce78b2 util.error: Extract error originator from stanza errors diff -r 1f84d0e4d0c4 -r 35d2260644d9 spec/util_error_spec.lua --- 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); diff -r 1f84d0e4d0c4 -r 35d2260644d9 util/error.lua --- 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