Skip to content

Commit

Permalink
format_result supports the new API error format
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekwegr committed Nov 7, 2022
1 parent d25f84a commit a050f10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/graphql_account_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ admin_register_user(Config) ->
Resp2 = register_user(Domain, Username, Password, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Resp2), <<"already registered">>)),
% Try to register a user without any name
Resp3 = register_user(Domain, <<"">>, Password, Config),
Resp3 = register_user(Domain, <<>>, Password, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Resp3), <<"Invalid JID">>)).

admin_register_random_user(Config) ->
Expand Down
7 changes: 1 addition & 6 deletions src/auth/ejabberd_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,7 @@ set_password(#jid{luser = LUser, lserver = LServer}, Password) ->
Opts = #{default => {error, not_allowed}},
case ejabberd_auth:does_user_exist(jid:make(LUser, LServer, <<>>)) of
true ->
case call_auth_modules_for_domain(LServer, F, Opts) of
{ok, Result} ->
{ok, Result};
Error ->
Error
end;
call_auth_modules_for_domain(LServer, F, Opts);
false ->
{error, not_allowed}
end.
Expand Down
10 changes: 5 additions & 5 deletions src/ejabberd_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ format_error(Error) ->
-spec format_result(In :: tuple() | atom() | integer() | string() | binary(),
{_, 'atom'|'integer'|'string'|'binary'}
) -> string() | {string(), _}.
format_result({error, Error}, _) ->
format_result(Code, {_Name, rescode}) ->
{"", make_status(Code)};
format_result({Code, Text}, {_Name, restuple}) ->
{io_lib:format("~s", [Text]), make_status(Code)};
format_result({Atom, Error}, _) when Atom =/= ok ->
{io_lib:format("Error: ~ts", [format_error(Error)]), make_status(error)};
format_result(Atom, {_Name, atom}) ->
io_lib:format("~p", [Atom]);
Expand All @@ -436,10 +440,6 @@ format_result(String, {_Name, string}) ->
io_lib:format("~s", [String]);
format_result(Binary, {_Name, binary}) ->
io_lib:format("~s", [Binary]);
format_result(Code, {_Name, rescode}) ->
{"", make_status(Code)};
format_result({Code, Text}, {_Name, restuple}) ->
{io_lib:format("~s", [Text]), make_status(Code)};
%% The result is a list of something: [something()]
format_result([], {_Name, {list, _ElementsDef}}) ->
"";
Expand Down

0 comments on commit a050f10

Please sign in to comment.