State2 = ejabberd_s2s_out:handle_auth_success(<<"dialback">>, State1),
ejabberd_s2s_out:establish(State2);
_ ->
- Reason = format_error(Result),
- ejabberd_s2s_out:handle_auth_failure(<<"dialback">>, {auth, Reason}, State1)
+ Reason = str:format("Peer responded with error: ~s",
+ [format_error(Result)]),
+ ejabberd_s2s_out:handle_auth_failure(
+ <<"dialback">>, {auth, Reason}, State1)
end;
s2s_out_packet(State, Pkt) when is_record(Pkt, db_result);
is_record(Pkt, db_verify) ->
From, <<"dialback">>, undefined, State1),
ejabberd_s2s_in:establish(State2);
_ ->
- Reason = format_error(Response),
+ Reason = str:format("Verification failed: ~s",
+ [format_error(Response)]),
ejabberd_s2s_in:handle_auth_failure(
From, <<"dialback">>, Reason, State1)
end.
format_error(#db_result{type = error, sub_els = Els}) ->
%% TODO: improve xmpp.erl
case xmpp:get_error(#message{sub_els = Els}) of
- #stanza_error{reason = Reason} ->
- erlang:atom_to_binary(Reason, latin1);
+ #stanza_error{} = Err ->
+ format_stanza_error(Err);
undefined ->
<<"unrecognized error">>
end;
format_error(_) ->
<<"unexpected dialback result">>.
+
+-spec format_stanza_error(stanza_error()) -> binary().
+format_stanza_error(#stanza_error{reason = Reason, text = Txt}) ->
+ Slogan = case Reason of
+ undefined -> <<"no reason">>;
+ #gone{} -> <<"gone">>;
+ #redirect{} -> <<"redirect">>;
+ _ -> erlang:atom_to_binary(Reason, latin1)
+ end,
+ case Txt of
+ undefined -> Slogan;
+ #text{data = <<"">>} -> Slogan;
+ #text{data = Data} ->
+ <<Data/binary, " (", Slogan/binary, ")">>
+ end.