# HG changeset patch # User Kim Alvefur # Date 1546198259 -3600 # Node ID 9361bd1b9c9b99a50929648ffb8277b7381d0ac4 # Parent 99199b53019f6d56db83085ebf8495d759a30158 util.error: Add a function for creating an error object from an error stanza diff -r 99199b53019f -r 9361bd1b9c9b util/error.lua --- 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; }