Software /
code /
prosody
Comparison
plugins/mod_vcard_legacy.lua @ 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 |
parent | 9267:37e2cace1f2a |
child | 9269:6097dc7d4847 |
comparison
equal
deleted
inserted
replaced
9267:37e2cace1f2a | 9268:628b99811301 |
---|---|
10 | 10 |
11 module:add_feature("vcard-temp"); | 11 module:add_feature("vcard-temp"); |
12 module:hook("account-disco-info", function (event) | 12 module:hook("account-disco-info", function (event) |
13 event.reply:tag("feature", { var = "urn:xmpp:pep-vcard-conversion:0" }):up(); | 13 event.reply:tag("feature", { var = "urn:xmpp:pep-vcard-conversion:0" }):up(); |
14 end); | 14 end); |
15 | |
16 local function handle_error(origin, stanza, err) | |
17 if err == "forbidden" then | |
18 origin.send(st.error_reply(stanza, "auth", "forbidden")); | |
19 elseif err == "internal-server-error" then | |
20 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); | |
21 else | |
22 origin.send(st.error_reply(stanza, "modify", "undefined-condition", err)); | |
23 end | |
24 end | |
15 | 25 |
16 -- Simple translations | 26 -- Simple translations |
17 -- <foo><text>hey</text></foo> -> <FOO>hey</FOO> | 27 -- <foo><text>hey</text></foo> -> <FOO>hey</FOO> |
18 local simple_map = { | 28 local simple_map = { |
19 nickname = "text"; | 29 nickname = "text"; |
238 end | 248 end |
239 | 249 |
240 local ok, err = pep_service:publish("urn:xmpp:vcard4", origin.full_jid, "current", vcard4); | 250 local ok, err = pep_service:publish("urn:xmpp:vcard4", origin.full_jid, "current", vcard4); |
241 if ok then | 251 if ok then |
242 origin.send(st.reply(stanza)); | 252 origin.send(st.reply(stanza)); |
243 elseif err == "forbidden" then | |
244 origin.send(st.error_reply(stanza, "auth", "forbidden")); | |
245 elseif err == "internal-server-error" then | |
246 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); | |
247 else | 253 else |
248 origin.send(st.error_reply(stanza, "modify", "undefined-condition", err)); | 254 handle_error(origin, stanza, err); |
249 end | 255 end |
250 | 256 |
251 return true; | 257 return true; |
252 end); | 258 end); |
253 | 259 |