aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/util_error_spec.lua3
-rw-r--r--util/error.lua7
2 files changed, 8 insertions, 2 deletions
diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua
index 136f8b12..9cb1c57b 100644
--- a/spec/util_error_spec.lua
+++ b/spec/util_error_spec.lua
@@ -48,12 +48,13 @@ 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");
+ 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 --git a/util/error.lua b/util/error.lua
index e0b1f9a6..c2b7d149 100644
--- a/util/error.lua
+++ b/util/error.lua
@@ -93,12 +93,17 @@ end
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