mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Return proper error message for duplicate or missing args in http_api call
This commit is contained in:
parent
65a6532cd9
commit
623a9ec3ba
@ -330,19 +330,23 @@ handle2(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
|
|||||||
format_command_result(Call, Auth, Res, Version)
|
format_command_result(Call, Auth, Res, Version)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_elem_delete(A, L, F) ->
|
get_elem_delete(Call, A, L, F) ->
|
||||||
case proplists:get_all_values(A, L) of
|
case proplists:get_all_values(A, L) of
|
||||||
[Value] -> {Value, proplists:delete(A, L)};
|
[Value] -> {Value, proplists:delete(A, L)};
|
||||||
[_, _ | _] ->
|
[_, _ | _] ->
|
||||||
%% Crash reporting the error
|
?INFO_MSG("Command ~s call rejected, it has duplicate attribute ~w",
|
||||||
exit({duplicated_attribute, A, L});
|
[Call, A]),
|
||||||
|
throw({invalid_parameter,
|
||||||
|
io_lib:format("Request have duplicate argument: ~w", [A])});
|
||||||
[] ->
|
[] ->
|
||||||
case F of
|
case F of
|
||||||
{list, _} ->
|
{list, _} ->
|
||||||
{[], L};
|
{[], L};
|
||||||
_ ->
|
_ ->
|
||||||
%% Report the error and then force a crash
|
?INFO_MSG("Command ~s call rejected, missing attribute ~w",
|
||||||
exit({attribute_not_found, A, L})
|
[Call, A]),
|
||||||
|
throw({invalid_parameter,
|
||||||
|
io_lib:format("Request have missing argument: ~w", [A])})
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -351,7 +355,7 @@ format_args(Call, Args, ArgsFormat) ->
|
|||||||
ArgFormat},
|
ArgFormat},
|
||||||
{Args1, Res}) ->
|
{Args1, Res}) ->
|
||||||
{ArgValue, Args2} =
|
{ArgValue, Args2} =
|
||||||
get_elem_delete(ArgName,
|
get_elem_delete(Call, ArgName,
|
||||||
Args1, ArgFormat),
|
Args1, ArgFormat),
|
||||||
Formatted = format_arg(ArgValue,
|
Formatted = format_arg(ArgValue,
|
||||||
ArgFormat),
|
ArgFormat),
|
||||||
|
Loading…
Reference in New Issue
Block a user