Diff

util/error.lua @ 9749:9361bd1b9c9b

util.error: Add a function for creating an error object from an error stanza
author Kim Alvefur <zash@zash.se>
date Sun, 30 Dec 2018 20:30:59 +0100
parent 9746:848fd204708c
child 10069:6f317e51544d
line wrap: on
line diff
--- 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;
 }