Comparison

util/error.lua @ 11094:03fdf41fd948

util.error: Pass converted stanza errors throguh new() In order to benefit from common processing
author Kim Alvefur <zash@zash.se>
date Sun, 27 Sep 2020 00:17:48 +0200
parent 11092:bd13aa89262d
child 11095:1ea3574b19c8
comparison
equal deleted inserted replaced
11093:ec14d4fce855 11094:03fdf41fd948
89 }, { wrapped_error = err }); 89 }, { wrapped_error = err });
90 90
91 return ok, new_err, ...; 91 return ok, new_err, ...;
92 end 92 end
93 93
94 local function from_stanza(stanza, context) 94 local function from_stanza(stanza, context, source)
95 local error_type, condition, text, extra_tag = stanza:get_error(); 95 local error_type, condition, text, extra_tag = stanza:get_error();
96 local error_tag = stanza:get_child("error"); 96 local error_tag = stanza:get_child("error");
97 context = context or {}; 97 context = context or {};
98 context.stanza = stanza; 98 context.stanza = stanza;
99 context.by = error_tag.attr.by or stanza.attr.from; 99 context.by = error_tag.attr.by or stanza.attr.from;
100 100
101 return setmetatable({ 101 return new({
102 type = error_type or "cancel"; 102 type = error_type or "cancel";
103 condition = condition or "undefined-condition"; 103 condition = condition or "undefined-condition";
104 text = text; 104 text = text;
105 extra = (extra_tag or condition == "gone") and { 105 extra = (extra_tag or condition == "gone") and {
106 uri = error_tag:get_child_text("gone", "urn:ietf:params:xml:ns:xmpp-stanzas"); 106 uri = error_tag:get_child_text("gone", "urn:ietf:params:xml:ns:xmpp-stanzas");
107 tag = extra_tag; 107 tag = extra_tag;
108 } or nil; 108 } or nil;
109 109 }, context, nil, source);
110 context = context;
111
112 }, error_mt);
113 end 110 end
114 111
115 return { 112 return {
116 new = new; 113 new = new;
117 init = init; 114 init = init;