Diff

mod_pubsub_feed/mod_pubsub_feed.lua @ 300:b81e4f86a231

mod_pubsub_feed: Catch and handle errors when publishing
author Kim Alvefur <zash@zash.se>
date Sun, 26 Dec 2010 19:05:39 +0100
parent 299:801066bf5793
child 322:637dc0a04052
line wrap: on
line diff
--- a/mod_pubsub_feed/mod_pubsub_feed.lua	Sun Dec 26 18:59:13 2010 +0100
+++ b/mod_pubsub_feed/mod_pubsub_feed.lua	Sun Dec 26 19:05:39 2010 +0100
@@ -73,7 +73,24 @@
 					local item = st.stanza("item", { id = id }):add_child(entry);
 
 					module:log("debug", "publishing to %s, id %s", node, id);
-					modules.pubsub.service:publish(node, actor, id, item)
+					local ok, err = modules.pubsub.service:publish(node, actor, id, item);
+					if not ok then
+						if err == "item-not-found" then -- try again
+							module:log("debug", "got item-not-found, creating %s and trying again", node);
+							local ok, err = modules.pubsub.service:create(node, actor);
+							if not ok then
+								module:log("error", "could not create node: %s", err);
+								return;
+							end
+							local ok, err = modules.pubsub.service:publish(node, actor, id, item);
+							if not ok then
+								module:log("error", "still could not create node: %s", err);
+								return
+							end
+						else
+							module:log("error", "publish failed: %s", err);
+						end
+					end
 				end
 			end
 		end);