]> granicus.if.org Git - ejabberd/commitdiff
Improve logging of dialback failures
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 28 Feb 2017 07:13:09 +0000 (10:13 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 28 Feb 2017 07:13:09 +0000 (10:13 +0300)
src/mod_s2s_dialback.erl

index d48bda2d9efd936442a9932fdb2330e772e0262c..4d9ae1af28b07ba600e6bc40016563386d762060 100644 (file)
@@ -248,8 +248,10 @@ s2s_out_packet(#{server := LServer, remote_server := RServer} = State,
            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) ->
@@ -298,7 +300,8 @@ send_db_result(State, #db_verify{from = From, to = To,
                       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.
@@ -334,10 +337,25 @@ format_error(#db_result{type = invalid}) ->
 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.