Skip to content

Commit 80313ad

Browse files
authored
Merge pull request #196 from giusdp/main
Fix 404 when list functions request on non-existent module
2 parents 7c3faeb + 67caa32 commit 80313ad

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

apps/core/lib/core_web/controllers/module_controller.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ defmodule CoreWeb.ModuleController do
3636
end
3737

3838
def show_functions(conn, %{"module_name" => name}) do
39-
functions = Modules.get_functions_in_module(name)
40-
render(conn, "show_functions.json", %{module_name: name, functions: functions})
39+
with {:ok, %Module{}} <- Modules.get_module_by_name(name) do
40+
functions = Modules.get_functions_in_module(name)
41+
render(conn, "show_functions.json", %{module_name: name, functions: functions})
42+
end
4143
end
4244

4345
def update(conn, %{"module_name" => name, "module" => module_params}) do

apps/core/test/core_web/integration/controllers/module_controller_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ defmodule CoreWeb.ModuleControllerTest do
5757
assert json_response(conn, 200)["data"] ==
5858
%{"functions" => [%{"name" => "some_name"}], "name" => module.name}
5959
end
60+
61+
test "show_functions: list request on non-existend module fails", %{conn: conn} do
62+
conn = get(conn, Routes.module_path(conn, :show_functions, "non_existent_module"))
63+
assert json_response(conn, 404)
64+
end
6065
end
6166

6267
describe "create module" do

0 commit comments

Comments
 (0)