aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-12-30 20:30:59 +0100
committerKim Alvefur <zash@zash.se>2018-12-30 20:30:59 +0100
commitac2d2297b62ba2973c49d7d5bee3927cef64ea97 (patch)
tree34db7e2c0d64d1d9131bdbf48aecfd2721e97fd4 /util
parentad3e5fd42bd1dddd478fffd412a842e98c735e9a (diff)
downloadprosody-ac2d2297b62ba2973c49d7d5bee3927cef64ea97.tar.gz
prosody-ac2d2297b62ba2973c49d7d5bee3927cef64ea97.zip
util.error: Add a function for creating an error object from an error stanza
Diffstat (limited to 'util')
-rw-r--r--util/error.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/error.lua b/util/error.lua
index ed61793f..344dd274 100644
--- a/util/error.lua
+++ b/util/error.lua
@@ -33,8 +33,20 @@ local function coerce(ok, err, ...)
return ok, new_err, ...;
end
+local function from_stanza(stanza, context)
+ local error_type, condition, text = stanza:get_error();
+ return setmetatable({
+ type = error_type or "cancel";
+ condition = condition or "undefined-condition";
+ text = text;
+
+ context = context or { stanza = stanza };
+ }, error_mt);
+end
+
return {
new = new;
coerce = coerce;
is_err = is_err;
+ from_stanza = from_stanza;
}