Changeset

9268:628b99811301

mod_vcard_legacy: Factor out error handling into a function This is a lite version of pubsub_error_reply() in mod_pubsub
author Kim Alvefur <zash@zash.se>
date Thu, 06 Sep 2018 23:33:44 +0200
parents 9267:37e2cace1f2a
children 9269:6097dc7d4847
files plugins/mod_vcard_legacy.lua
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_vcard_legacy.lua	Thu Sep 06 23:05:38 2018 +0200
+++ b/plugins/mod_vcard_legacy.lua	Thu Sep 06 23:33:44 2018 +0200
@@ -13,6 +13,16 @@
 	event.reply:tag("feature", { var = "urn:xmpp:pep-vcard-conversion:0" }):up();
 end);
 
+local function handle_error(origin, stanza, err)
+	if err == "forbidden" then
+		origin.send(st.error_reply(stanza, "auth", "forbidden"));
+	elseif err == "internal-server-error" then
+		origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
+	else
+		origin.send(st.error_reply(stanza, "modify", "undefined-condition", err));
+	end
+end
+
 -- Simple translations
 -- <foo><text>hey</text></foo> -> <FOO>hey</FOO>
 local simple_map = {
@@ -240,12 +250,8 @@
 	local ok, err = pep_service:publish("urn:xmpp:vcard4", origin.full_jid, "current", vcard4);
 	if ok then
 		origin.send(st.reply(stanza));
-	elseif err == "forbidden" then
-		origin.send(st.error_reply(stanza, "auth", "forbidden"));
-	elseif err == "internal-server-error" then
-		origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
 	else
-		origin.send(st.error_reply(stanza, "modify", "undefined-condition", err));
+		handle_error(origin, stanza, err);
 	end
 
 	return true;