Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIM-1536 Return error 404 instead of 500 if GET command not found #3383

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions big_tests/tests/rest_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ blank_auth_testcases() ->
test_cases() ->
[commands_are_listed,
non_existent_command_returns404,
arcusfelis marked this conversation as resolved.
Show resolved Hide resolved
existent_command_with_missing_arguments_returns404,
user_can_be_registered_and_removed,
sessions_are_listed,
session_can_be_kicked,
Expand Down Expand Up @@ -206,6 +207,9 @@ commands_are_listed(_C) ->
non_existent_command_returns404(_C) ->
{?NOT_FOUND, _} = gett(admin, <<"/isitthereornot">>).

existent_command_with_missing_arguments_returns404(_C) ->
{?NOT_FOUND, _} = gett(admin, <<"/contacts/">>).

user_can_be_registered_and_removed(_Config) ->
% list users
{?OK, Lusers} = gett(admin, path("users")),
Expand Down
8 changes: 6 additions & 2 deletions src/mongoose_api_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ to_json(Req, #http_api_state{command_category = Category,
bindings = B} = State) ->
Cmds = mongoose_commands:list(admin, Category, method_to_action(<<"GET">>), SubCategory),
Arity = length(B),
[Command] = [C || C <- Cmds, mongoose_commands:arity(C) == Arity],
process_request(<<"GET">>, Command, Req, State).
case [C || C <- Cmds, mongoose_commands:arity(C) == Arity] of
[Command] ->
process_request(<<"GET">>, Command, Req, State);
[] ->
error_response(not_found, ?ARGS_LEN_ERROR, Req, State)
end.

%% @doc Called for a method of type "POST" and "PUT"
from_json(Req, #http_api_state{command_category = Category,
Expand Down