Software /
code /
prosody
Comparison
plugins/mod_pubsub/pubsub.lib.lua @ 13533:c885594f7f9a
mod_pubsub: Allow passing additional error context
Sometimes it is useful to pass additional information along.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 27 Oct 2024 15:23:45 +0100 |
parent | 13532:9970d333a63f |
child | 13535:88cab98aa28c |
comparison
equal
deleted
inserted
replaced
13532:9970d333a63f | 13533:c885594f7f9a |
---|---|
31 ["internal-server-error"] = { "wait", "internal-server-error" }; | 31 ["internal-server-error"] = { "wait", "internal-server-error" }; |
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) | 36 local function pubsub_error_reply(stanza, error, context) |
37 if type(error) == "table" and type(error.pubsub_condition) == "string" then | 37 if type(error) == "table" and type(error.pubsub_condition) == "string" then |
38 error.extra = { namespace = xmlns_pubsub_errors; condition = error.pubsub_condition } | 38 error.extra = { namespace = xmlns_pubsub_errors; condition = error.pubsub_condition } |
39 end | 39 end |
40 local reply = st.error_reply(stanza, pubsub_errors.wrap(error)); | 40 local reply = st.error_reply(stanza, pubsub_errors.wrap(error, context)); |
41 return reply; | 41 return reply; |
42 end | 42 end |
43 _M.pubsub_error_reply = pubsub_error_reply; | 43 _M.pubsub_error_reply = pubsub_error_reply; |
44 | 44 |
45 local function dataform_error_message(err) -- ({ string : string }) -> string? | 45 local function dataform_error_message(err) -- ({ string : string }) -> string? |
678 end | 678 end |
679 end | 679 end |
680 if item then | 680 if item then |
681 item.attr.publisher = service.config.normalize_jid(stanza.attr.from); | 681 item.attr.publisher = service.config.normalize_jid(stanza.attr.from); |
682 end | 682 end |
683 local ok, ret = service:publish(node, stanza.attr.from, id, item, required_config); | 683 local ok, ret, context = service:publish(node, stanza.attr.from, id, item, required_config); |
684 local reply; | 684 local reply; |
685 if ok then | 685 if ok then |
686 if type(ok) == "string" then | 686 if type(ok) == "string" then |
687 id = ok; | 687 id = ok; |
688 end | 688 end |
689 reply = st.reply(stanza) | 689 reply = st.reply(stanza) |
690 :tag("pubsub", { xmlns = xmlns_pubsub }) | 690 :tag("pubsub", { xmlns = xmlns_pubsub }) |
691 :tag("publish", { node = node }) | 691 :tag("publish", { node = node }) |
692 :tag("item", { id = id }); | 692 :tag("item", { id = id }); |
693 else | 693 else |
694 reply = pubsub_error_reply(stanza, ret); | 694 reply = pubsub_error_reply(stanza, ret, context); |
695 end | 695 end |
696 origin.send(reply); | 696 origin.send(reply); |
697 return true; | 697 return true; |
698 end | 698 end |
699 | 699 |