Comparison

plugins/mod_pubsub/pubsub.lib.lua @ 13535:88cab98aa28c

mod_pubsub: Move precondition error wrangling out of util.pubsub Removes dependency on util.error from util.pubsub which was only used for this one special case. Line count reduction! Would be even nicer if templating could be done by util.error itself.
author Kim Alvefur <zash@zash.se>
date Tue, 29 Oct 2024 14:56:02 +0100
parent 13533:c885594f7f9a
child 13550:eae0272b87e3
comparison
equal deleted inserted replaced
13534:d532176d4334 13535:88cab98aa28c
32 ["precondition-not-met"] = { "cancel", "conflict", nil, "precondition-not-met" }; 32 ["precondition-not-met"] = { "cancel", "conflict", nil, "precondition-not-met" };
33 ["invalid-item"] = { "modify", "bad-request", "invalid item" }; 33 ["invalid-item"] = { "modify", "bad-request", "invalid item" };
34 ["persistent-items-unsupported"] = { "cancel", "feature-not-implemented", nil, "persistent-items" }; 34 ["persistent-items-unsupported"] = { "cancel", "feature-not-implemented", nil, "persistent-items" };
35 }); 35 });
36 local function pubsub_error_reply(stanza, error, context) 36 local function pubsub_error_reply(stanza, error, context)
37 if type(error) == "table" and type(error.pubsub_condition) == "string" then 37 local err = pubsub_errors.wrap(error, context);
38 error.extra = { namespace = xmlns_pubsub_errors; condition = error.pubsub_condition } 38 if error == "precondition-not-met" and type(context) == "table" and type(context.field) == "string" then
39 end 39 err.text = "Field does not match: " .. context.field;
40 local reply = st.error_reply(stanza, pubsub_errors.wrap(error, context)); 40 end
41 local reply = st.error_reply(stanza, err);
41 return reply; 42 return reply;
42 end 43 end
43 _M.pubsub_error_reply = pubsub_error_reply; 44 _M.pubsub_error_reply = pubsub_error_reply;
44 45
45 local function dataform_error_message(err) -- ({ string : string }) -> string? 46 local function dataform_error_message(err) -- ({ string : string }) -> string?