mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
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.
This commit is contained in:
parent
e18522f74c
commit
abdbc5df13
@ -441,14 +441,32 @@ notify(#{jid := #jid{luser = LUser, lserver = LServer},
|
|||||||
notify(LUser, LServer, Clients, Pkt, Dir) ->
|
notify(LUser, LServer, Clients, Pkt, Dir) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({TS, PushLJID, Node, XData}) ->
|
fun({TS, PushLJID, Node, XData}) ->
|
||||||
HandleResponse = fun(#iq{type = result}) ->
|
HandleResponse =
|
||||||
ok;
|
fun(#iq{type = result}) ->
|
||||||
(#iq{type = error}) ->
|
?DEBUG("~s accepted notification for ~s@~s (~s)",
|
||||||
spawn(?MODULE, delete_session,
|
[jid:encode(PushLJID), LUser, LServer, Node]);
|
||||||
[LUser, LServer, TS]);
|
(#iq{type = error} = IQ) ->
|
||||||
(timeout) ->
|
case inspect_error(IQ) of
|
||||||
ok % Hmm.
|
{wait, Reason} ->
|
||||||
end,
|
?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)
|
notify(LServer, PushLJID, Node, XData, Pkt, Dir, HandleResponse)
|
||||||
end, Clients).
|
end, Clients).
|
||||||
|
|
||||||
@ -667,6 +685,15 @@ get_body_text(#message{body = Body} = Msg) ->
|
|||||||
body_is_encrypted(#message{sub_els = SubEls}) ->
|
body_is_encrypted(#message{sub_els = SubEls}) ->
|
||||||
lists:keyfind(<<"encrypted">>, #xmlel.name, SubEls) /= false.
|
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.
|
%% Caching.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user