util/error.lua
changeset 9753 9361bd1b9c9b
parent 9750 848fd204708c
child 10073 6f317e51544d
--- a/util/error.lua	Sun Dec 30 16:03:15 2018 +0100
+++ b/util/error.lua	Sun Dec 30 20:30:59 2018 +0100
@@ -33,8 +33,20 @@
 	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;
 }