summaryrefslogtreecommitdiff
path: root/src/mod_push.erl
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2019-02-11 22:29:49 +0100
committerHolger Weiss <holger@zedat.fu-berlin.de>2019-02-11 22:29:49 +0100
commitabdbc5df132309dddac7a539776d62aa86a88b99 (patch)
treeba1ae88202aec60f7fd2d15e2b81ade230340eed /src/mod_push.erl
parentOnce just_created isn't true, use it to keep room process creation (#2787) (diff)
mod_push: Improve notification error handling
Don't disable push notifications if the app server returned a temporary error, and log the app server's notification response.
Diffstat (limited to 'src/mod_push.erl')
-rw-r--r--src/mod_push.erl43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/mod_push.erl b/src/mod_push.erl
index 2aa69959..07772c0e 100644
--- a/src/mod_push.erl
+++ b/src/mod_push.erl
@@ -441,14 +441,32 @@ notify(#{jid := #jid{luser = LUser, lserver = LServer},
notify(LUser, LServer, Clients, Pkt, Dir) ->
lists:foreach(
fun({TS, PushLJID, Node, XData}) ->
- HandleResponse = fun(#iq{type = result}) ->
- ok;
- (#iq{type = error}) ->
- spawn(?MODULE, delete_session,
- [LUser, LServer, TS]);
- (timeout) ->
- ok % Hmm.
- end,
+ HandleResponse =
+ fun(#iq{type = result}) ->
+ ?DEBUG("~s accepted notification for ~s@~s (~s)",
+ [jid:encode(PushLJID), LUser, LServer, Node]);
+ (#iq{type = error} = IQ) ->
+ case inspect_error(IQ) of
+ {wait, Reason} ->
+ ?INFO_MSG("~s rejected notification for "
+ "~s@~s (~s) temporarily: ~s",
+ [jid:encode(PushLJID), LUser,
+ LServer, Node, Reason]);
+ {Type, Reason} ->
+ spawn(?MODULE, delete_session,
+ [LUser, LServer, TS]),
+ ?WARNING_MSG("~s rejected notification for "
+ "~s@~s (~s), disabling push: ~s "
+ "(~s)",
+ [jid:encode(PushLJID), LUser,
+ LServer, Node, Reason, Type])
+ end;
+ (timeout) ->
+ ?DEBUG("Timeout sending notification for ~s@~s (~s) "
+ "to ~s",
+ [LUser, LServer, Node, jid:encode(PushLJID)]),
+ ok % Hmm.
+ end,
notify(LServer, PushLJID, Node, XData, Pkt, Dir, HandleResponse)
end, Clients).
@@ -667,6 +685,15 @@ get_body_text(#message{body = Body} = Msg) ->
body_is_encrypted(#message{sub_els = SubEls}) ->
lists:keyfind(<<"encrypted">>, #xmlel.name, SubEls) /= false.
+-spec inspect_error(iq()) -> {atom(), binary()}.
+inspect_error(IQ) ->
+ case xmpp:get_error(IQ) of
+ #stanza_error{type = Type} = Err ->
+ {Type, xmpp:format_stanza_error(Err)};
+ undefined ->
+ {undefined, <<"unrecognized error">>}
+ end.
+
%%--------------------------------------------------------------------
%% Caching.
%%--------------------------------------------------------------------