diff options
author | Kim Alvefur <zash@zash.se> | 2024-10-27 15:18:24 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2024-10-27 15:18:24 +0100 |
commit | 9dd5775dce8ca965899a9198584311ccce6c1732 (patch) | |
tree | 492ce4a9cda7e333fde15c56f28a705dc94c4982 /plugins/mod_pubsub | |
parent | 91f9db5ffce2367e2370a93fefb81ac3923f99d8 (diff) | |
download | prosody-9dd5775dce8ca965899a9198584311ccce6c1732.tar.gz prosody-9dd5775dce8ca965899a9198584311ccce6c1732.zip |
mod_pubsub: Use error registry
This is what util.error was made for!
This replaces the custom error stanza builder with common code in
util.stanza that knows enough about util.error and namespaced errors.
Some awkwardness remains in the way util.pubsub returns conflicting
form fields.
Diffstat (limited to 'plugins/mod_pubsub')
-rw-r--r-- | plugins/mod_pubsub/pubsub.lib.lua | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index 8ae0a896..a7379ab3 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -1,4 +1,3 @@ -local t_unpack = table.unpack; local time_now = os.time; local jid_prep = require "prosody.util.jid".prep; @@ -18,7 +17,7 @@ local _M = {}; local handlers = {}; _M.handlers = handlers; -local pubsub_errors = { +local pubsub_errors = errors.init("pubsub", xmlns_pubsub_errors, { ["conflict"] = { "cancel", "conflict" }; ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" }; ["jid-required"] = { "modify", "bad-request", nil, "jid-required" }; @@ -33,16 +32,12 @@ local pubsub_errors = { ["precondition-not-met"] = { "cancel", "conflict", nil, "precondition-not-met" }; ["invalid-item"] = { "modify", "bad-request", "invalid item" }; ["persistent-items-unsupported"] = { "cancel", "feature-not-implemented", nil, "persistent-items" }; -}; +}); local function pubsub_error_reply(stanza, error) - local e = pubsub_errors[error]; - if not e and errors.is_err(error) then - e = { error.type, error.condition, error.text, error.pubsub_condition }; - end - local reply = st.error_reply(stanza, t_unpack(e, 1, 3)); - if e[4] then - reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up(); + if type(error) == "table" and type(error.pubsub_condition) == "string" then + error.extra = { namespace = xmlns_pubsub_errors; condition = error.pubsub_condition } end + local reply = st.error_reply(stanza, pubsub_errors.wrap(error)); return reply; end _M.pubsub_error_reply = pubsub_error_reply; |