comparison mod_unified_push/mod_unified_push.lua @ 6562:5da6fb562df9 default tip

mod_unified_push: Fix push error handling (fixes #2000) Use the error object that send_iq() passes as an argument to it's reject callback instead of attempting and failing to do the parsing in the callback itself.
author kmq
date Mon, 06 Jul 2026 14:23:57 +0200
parents b00638d74f46
children
comparison
equal deleted inserted replaced
6561:93544117ddcd 6562:5da6fb562df9
180 local push_iq = st.iq({ type = "set", to = data.sub, from = module.host, id = push_id }) 180 local push_iq = st.iq({ type = "set", to = data.sub, from = module.host, id = push_id })
181 :text_tag("push", base64.encode(payload), { instance = data.instance, application = data.application, xmlns = xmlns_up }); 181 :text_tag("push", base64.encode(payload), { instance = data.instance, application = data.application, xmlns = xmlns_up });
182 return module:send_iq(push_iq):next(function () 182 return module:send_iq(push_iq):next(function ()
183 module:log("debug", "Push notification delivered [%s]", push_id); 183 module:log("debug", "Push notification delivered [%s]", push_id);
184 return 201; 184 return 201;
185 end, function (error_event) 185 end, function (err)
186 local e_type, e_cond, e_text = error_event.stanza:get_error(); 186 if err.condition == "item-not-found" or err.condition == "feature-not-implemented" then
187 if e_cond == "item-not-found" or e_cond == "feature-not-implemented" then
188 module:log("debug", "Push rejected [%s]", push_id); 187 module:log("debug", "Push rejected [%s]", push_id);
189 return 404; 188 return 404;
190 elseif e_cond == "service-unavailable" or e_cond == "recipient-unavailable" then 189 elseif err.condition == "service-unavailable" or err.condition == "recipient-unavailable" then
191 module:log("debug", "Recipient temporarily unavailable [%s]", push_id); 190 module:log("debug", "Recipient temporarily unavailable [%s]", push_id);
192 return 503; 191 return 503;
193 end 192 end
194 module:log("warn", "Unexpected push error response: %s/%s/%s", e_type, e_cond, e_text); 193 module:log("warn", "Unexpected push error response: %s/%s/%s", err.type, err.condition, err.text);
195 return 500; 194 return 500;
196 end); 195 end);
197 end 196 end
198 197
199 module:provides("http", { 198 module:provides("http", {