change_shaper(State),
Conn = get_conn_type(State),
State1 = State#{conn => Conn, resource => R, jid => JID},
- Prio = try maps:get(pres_last, State) of
+ Prio = case maps:get(pres_last, State, undefined) of
+ undefined -> undefined;
Pres -> get_priority_from_presence(Pres)
- catch _:{badkey, _} ->
- undefined
end,
Info = [{ip, IP}, {conn, Conn}, {auth_module, AuthModule}],
ejabberd_sm:open_session(SID, U, S, R, Prio, Info),
State1
end;
process_info(State, force_update_presence) ->
- try maps:get(pres_last, State) of
+ case maps:get(pres_last, State, error) of
+ error -> State;
Pres -> process_self_presence(State, Pres)
- catch _:{badkey, _} ->
- State
end;
process_info(State, Info) ->
?WARNING_MSG("got unexpected info: ~p", [Info]),
ejabberd_hooks:run_fold(c2s_init, {ok, State1}, [Opts]).
handle_call(get_presence, From, #{jid := JID} = State) ->
- Pres = try maps:get(pres_last, State)
- catch _:{badkey, _} ->
+ Pres = case maps:get(pres_last, State, error) of
+ error ->
BareJID = jid:remove_resource(JID),
- #presence{from = JID, to = BareJID, type = unavailable}
+ #presence{from = JID, to = BareJID, type = unavailable};
+ P -> P
end,
reply(From, Pres),
State;
queue_in(Key, Type, Val, {N, Seq, Q}) ->
Seq1 = Seq + 1,
Time = {Seq1, p1_time_compat:timestamp()},
- try maps:get(Key, Q) of
+ case maps:get(Key, Q, error) of
+ error ->
+ Q1 = maps:put(Key, [{Type, Time, Val}], Q),
+ {N + 1, Seq1, Q1};
TypeVals ->
case lists:keymember(Type, 1, TypeVals) of
true ->
Q1 = maps:put(Key, TypeVals1, Q),
{N + 1, Seq1, Q1}
end
- catch _:{badkey, _} ->
- Q1 = maps:put(Key, [{Type, Time, Val}], Q),
- {N + 1, Seq1, Q1}
end.
-spec queue_take(term(), csi_queue()) -> {list(), csi_queue()} | error.
Acc;
c2s_self_presence({#presence{type = available} = NewPres, State} = Acc) ->
NewPrio = get_priority_from_presence(NewPres),
- LastPrio = try maps:get(pres_last, State) of
+ LastPrio = case maps:get(pres_last, State, error) of
+ error -> -1;
LastPres -> get_priority_from_presence(LastPres)
- catch _:{badkey, _} ->
- -1
end,
if LastPrio < 0 andalso NewPrio >= 0 ->
route_offline_messages(State);
-> {ok, binary()} | {error, atom(), binary()}.
authenticate(#{xmlns := ?NS_SERVER, sockmod := SockMod,
socket := Socket} = State, Authzid) ->
- Peer = try maps:get(remote_server, State)
- catch _:{badkey, _} -> Authzid
- end,
+ Peer = maps:get(remote_server, State, Authzid),
case SockMod:get_peer_certificate(Socket) of
{ok, Cert} ->
case SockMod:get_verify_result(Socket) of