changeset 5154:48ca519cd66a

mod_unified_push: Improved error handling and reporting
author Matthew Wild <mwild1@gmail.com>
date Sat, 14 Jan 2023 16:16:47 +0000
parents d69cc9a23fad
children 18ed655c755d
files mod_unified_push/mod_unified_push.lua
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mod_unified_push/mod_unified_push.lua	Sat Jan 14 16:16:00 2023 +0000
+++ b/mod_unified_push/mod_unified_push.lua	Sat Jan 14 16:16:47 2023 +0000
@@ -106,12 +106,13 @@
 
 local function register_route(params)
 	local expiry = os.time() + push_registration_ttl;
-	local token = backends[backend].sign({
+	local token, err = backends[backend].sign({
 		instance = params.instance;
 		application = params.application;
 		sub = params.jid;
 		exp = expiry;
 	});
+	if not token then return nil, err; end
 	return {
 		url = module:http_url("push").."/"..urlencode(token);
 		expiry = expiry;
@@ -120,26 +121,30 @@
 
 -- Handle incoming registration from XMPP client
 function handle_register(event)
+	module:log("debug", "Push registration request received");
 	local origin, stanza = event.origin, event.stanza;
 	if not is_jid_permitted(stanza.attr.from) then
-		return st.error_reply(stanza, "auth", "forbidden");
+		module:log("debug", "Sender <%s> not permitted to register on this UnifiedPush service", stanza.attr.from);
+		return origin.send(st.error_reply(stanza, "auth", "forbidden"));
 	end
 	local instance, instance_err = check_sha256(stanza.tags[1].attr.instance);
 	if not instance then
-		return st.error_reply(stanza, "modify", "bad-request", "instance: "..instance_err);
+		return origin.send(st.error_reply(stanza, "modify", "bad-request", "instance: "..instance_err));
 	end
 	local application, application_err = check_sha256(stanza.tags[1].attr.application);
 	if not application then
-		return st.error_reply(stanza, "modify", "bad-request", "application: "..application_err);
+		return origin.send(st.error_reply(stanza, "modify", "bad-request", "application: "..application_err));
 	end
-	local route = register_route({
+
+	local route, register_err = register_route({
 		instance = instance;
 		application = application;
 		jid = stanza.attr.from;
 	});
 
 	if not route then
-		return st.error_reply(stanza, "wait", "internal-server-error");
+		module:log("warn", "Failed to create registration using %s backend: %s", backend, register_err);
+		return origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
 	end
 
 	module:log("debug", "New push registration successful");