From bd064fa3fc96dc765d9db4442073da51f14d593a Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Mon, 11 Dec 2017 09:46:26 +0300 Subject: Use xmpp:try_subtag/2 wherever possible --- src/mod_legacy_auth.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/mod_legacy_auth.erl') diff --git a/src/mod_legacy_auth.erl b/src/mod_legacy_auth.erl index 722a05738..0ae3253c9 100644 --- a/src/mod_legacy_auth.erl +++ b/src/mod_legacy_auth.erl @@ -61,11 +61,16 @@ mod_opt_type(_) -> c2s_state() | {stop, c2s_state()}. c2s_unauthenticated_packet(State, #iq{type = T, sub_els = [_]} = IQ) when T == get; T == set -> - case xmpp:get_subtag(IQ, #legacy_auth{}) of + try xmpp:try_subtag(IQ, #legacy_auth{}) of #legacy_auth{} = Auth -> {stop, authenticate(State, xmpp:set_els(IQ, [Auth]))}; false -> State + catch _:{xmpp_codec, Why} -> + Txt = xmpp:io_format_error(Why), + Lang = maps:get(lang, State), + Err = xmpp:make_error(IQ, xmpp:error_bad_request(Txt, Lang)), + {stop, ejabberd_c2s:send(State, Err)} end; c2s_unauthenticated_packet(State, _) -> State. -- cgit v1.2.3