mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Use error formatting functions from xmpp library
This commit is contained in:
parent
c4c91cc956
commit
ac31c85866
@ -25,7 +25,7 @@
|
|||||||
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.22"}}},
|
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.22"}}},
|
||||||
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.11"}}},
|
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.11"}}},
|
||||||
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.30"}}},
|
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.30"}}},
|
||||||
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "5745b7e"}},
|
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "cb39f8b"}},
|
||||||
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.14"}}},
|
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.14"}}},
|
||||||
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
||||||
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
|
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
|
||||||
|
@ -335,24 +335,9 @@ format_error(#db_result{type = invalid}) ->
|
|||||||
format_error(#db_result{type = error} = Result) ->
|
format_error(#db_result{type = error} = Result) ->
|
||||||
case xmpp:get_error(Result) of
|
case xmpp:get_error(Result) of
|
||||||
#stanza_error{} = Err ->
|
#stanza_error{} = Err ->
|
||||||
format_stanza_error(Err);
|
xmpp:format_stanza_error(Err);
|
||||||
undefined ->
|
undefined ->
|
||||||
<<"unrecognized error">>
|
<<"unrecognized error">>
|
||||||
end;
|
end;
|
||||||
format_error(_) ->
|
format_error(_) ->
|
||||||
<<"unexpected dialback result">>.
|
<<"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 xmpp:get_text(Txt) of
|
|
||||||
<<"">> ->
|
|
||||||
Slogan;
|
|
||||||
Data ->
|
|
||||||
<<Data/binary, " (", Slogan/binary, ")">>
|
|
||||||
end.
|
|
||||||
|
@ -196,10 +196,10 @@ format_error({socket, Reason}) ->
|
|||||||
format("Connection failed: ~s", [format_inet_error(Reason)]);
|
format("Connection failed: ~s", [format_inet_error(Reason)]);
|
||||||
format_error({stream, reset}) ->
|
format_error({stream, reset}) ->
|
||||||
<<"Stream reset by peer">>;
|
<<"Stream reset by peer">>;
|
||||||
format_error({stream, {in, #stream_error{reason = Reason, text = Txt}}}) ->
|
format_error({stream, {in, #stream_error{} = Err}}) ->
|
||||||
format("Stream closed by peer: ~s", [format_stream_error(Reason, Txt)]);
|
format("Stream closed by peer: ~s", [xmpp:format_stream_error(Err)]);
|
||||||
format_error({stream, {out, #stream_error{reason = Reason, text = Txt}}}) ->
|
format_error({stream, {out, #stream_error{} = Err}}) ->
|
||||||
format("Stream closed by us: ~s", [format_stream_error(Reason, Txt)]);
|
format("Stream closed by us: ~s", [xmpp:format_stream_error(Err)]);
|
||||||
format_error({tls, Reason}) ->
|
format_error({tls, Reason}) ->
|
||||||
format("TLS failed: ~s", [format_tls_error(Reason)]);
|
format("TLS failed: ~s", [format_tls_error(Reason)]);
|
||||||
format_error(internal_failure) ->
|
format_error(internal_failure) ->
|
||||||
@ -1156,20 +1156,6 @@ format_inet_error(Reason) ->
|
|||||||
Txt -> Txt
|
Txt -> Txt
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec format_stream_error(atom() | 'see-other-host'(), [text()]) -> string().
|
|
||||||
format_stream_error(Reason, Txt) ->
|
|
||||||
Slogan = case Reason of
|
|
||||||
undefined -> "no reason";
|
|
||||||
#'see-other-host'{} -> "see-other-host";
|
|
||||||
_ -> atom_to_list(Reason)
|
|
||||||
end,
|
|
||||||
case xmpp:get_text(Txt) of
|
|
||||||
<<"">> ->
|
|
||||||
Slogan;
|
|
||||||
Data ->
|
|
||||||
binary_to_list(Data) ++ " (" ++ Slogan ++ ")"
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec format_sasl_error(cyrsasl:mechanism(), atom()) -> {atom(), binary()}.
|
-spec format_sasl_error(cyrsasl:mechanism(), atom()) -> {atom(), binary()}.
|
||||||
format_sasl_error(<<"EXTERNAL">>, Err) ->
|
format_sasl_error(<<"EXTERNAL">>, Err) ->
|
||||||
xmpp_stream_pkix:format_error(Err);
|
xmpp_stream_pkix:format_error(Err);
|
||||||
|
@ -217,10 +217,10 @@ format_error({pkix, Reason}) ->
|
|||||||
format("Peer certificate rejected: ~s", [ErrTxt]);
|
format("Peer certificate rejected: ~s", [ErrTxt]);
|
||||||
format_error({stream, reset}) ->
|
format_error({stream, reset}) ->
|
||||||
<<"Stream reset by peer">>;
|
<<"Stream reset by peer">>;
|
||||||
format_error({stream, {in, #stream_error{reason = Reason, text = Txt}}}) ->
|
format_error({stream, {in, #stream_error{} = Err}}) ->
|
||||||
format("Stream closed by peer: ~s", [format_stream_error(Reason, Txt)]);
|
format("Stream closed by peer: ~s", [xmpp:format_stream_error(Err)]);
|
||||||
format_error({stream, {out, #stream_error{reason = Reason, text = Txt}}}) ->
|
format_error({stream, {out, #stream_error{} = Err}}) ->
|
||||||
format("Stream closed by us: ~s", [format_stream_error(Reason, Txt)]);
|
format("Stream closed by us: ~s", [xmpp:format_stream_error(Err)]);
|
||||||
format_error({tls, Reason}) ->
|
format_error({tls, Reason}) ->
|
||||||
format("TLS failed: ~s", [format_tls_error(Reason)]);
|
format("TLS failed: ~s", [format_tls_error(Reason)]);
|
||||||
format_error({auth, Reason}) ->
|
format_error({auth, Reason}) ->
|
||||||
@ -672,7 +672,7 @@ process_sasl_success(#{socket := Socket} = State) ->
|
|||||||
-spec process_sasl_failure(sasl_failure() | binary(), state()) -> state().
|
-spec process_sasl_failure(sasl_failure() | binary(), state()) -> state().
|
||||||
process_sasl_failure(#sasl_failure{} = Failure, State) ->
|
process_sasl_failure(#sasl_failure{} = Failure, State) ->
|
||||||
Reason = format("Peer responded with error: ~s",
|
Reason = format("Peer responded with error: ~s",
|
||||||
[format_sasl_failure(Failure)]),
|
[xmpp:format_sasl_error(Failure)]),
|
||||||
process_sasl_failure(Reason, State);
|
process_sasl_failure(Reason, State);
|
||||||
process_sasl_failure(Reason, State) ->
|
process_sasl_failure(Reason, State) ->
|
||||||
try callback(handle_auth_failure, <<"EXTERNAL">>, {auth, Reason}, State)
|
try callback(handle_auth_failure, <<"EXTERNAL">>, {auth, Reason}, State)
|
||||||
@ -817,37 +817,12 @@ format_inet_error(Reason) ->
|
|||||||
Txt -> Txt
|
Txt -> Txt
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec format_stream_error(atom() | 'see-other-host'(), [text()]) -> string().
|
|
||||||
format_stream_error(Reason, Txt) ->
|
|
||||||
Slogan = case Reason of
|
|
||||||
undefined -> "no reason";
|
|
||||||
#'see-other-host'{} -> "see-other-host";
|
|
||||||
_ -> atom_to_list(Reason)
|
|
||||||
end,
|
|
||||||
case xmpp:get_text(Txt) of
|
|
||||||
<<"">> ->
|
|
||||||
Slogan;
|
|
||||||
Data ->
|
|
||||||
binary_to_list(Data) ++ " (" ++ Slogan ++ ")"
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec format_tls_error(atom() | binary()) -> list().
|
-spec format_tls_error(atom() | binary()) -> list().
|
||||||
format_tls_error(Reason) when is_atom(Reason) ->
|
format_tls_error(Reason) when is_atom(Reason) ->
|
||||||
format_inet_error(Reason);
|
format_inet_error(Reason);
|
||||||
format_tls_error(Reason) ->
|
format_tls_error(Reason) ->
|
||||||
binary_to_list(Reason).
|
binary_to_list(Reason).
|
||||||
|
|
||||||
format_sasl_failure(#sasl_failure{reason = Reason, text = Txt}) ->
|
|
||||||
Slogan = case Reason of
|
|
||||||
undefined -> "no reason";
|
|
||||||
_ -> atom_to_list(Reason)
|
|
||||||
end,
|
|
||||||
case xmpp:get_text(Txt) of
|
|
||||||
<<"">> -> Slogan;
|
|
||||||
Data ->
|
|
||||||
binary_to_list(Data) ++ " (" ++ Slogan ++ ")"
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec format(io:format(), list()) -> binary().
|
-spec format(io:format(), list()) -> binary().
|
||||||
format(Fmt, Args) ->
|
format(Fmt, Args) ->
|
||||||
iolist_to_binary(io_lib:format(Fmt, Args)).
|
iolist_to_binary(io_lib:format(Fmt, Args)).
|
||||||
|
Loading…
Reference in New Issue
Block a user