Skip to content

Commit 3c4e986

Browse files
author
José Valim
committed
Improve missing param error message
1 parent 43b5fba commit 3c4e986

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/phoenix/exceptions.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ defmodule Phoenix.MissingParamError do
1515
defexception [:message, plug_status: 400]
1616

1717
def exception([key: value]) do
18-
msg = "expected key for #{inspect value} to be present"
18+
msg = "expected key #{inspect value} to be present in params, " <>
19+
"please send the expected key or adapt your scrub_params/2 call"
1920
%Phoenix.MissingParamError{message: msg}
2021
end
2122
end

test/phoenix/controller/controller_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ defmodule Phoenix.Controller.ControllerTest do
333333
end
334334

335335
test "scrub_params/2 raises Phoenix.MissingParamError for missing key" do
336-
assert_raise(Phoenix.MissingParamError, "expected key for \"foo\" to be present", fn ->
336+
assert_raise(Phoenix.MissingParamError, ~r"expected key \"foo\" to be present in params", fn ->
337337
conn(:get, "/") |> fetch_query_params |> scrub_params("foo")
338338
end)
339339

340-
assert_raise(Phoenix.MissingParamError, "expected key for \"foo\" to be present", fn ->
340+
assert_raise(Phoenix.MissingParamError, ~r"expected key \"foo\" to be present in params", fn ->
341341
conn(:get, "/?foo=") |> fetch_query_params |> scrub_params("foo")
342342
end)
343343
end

0 commit comments

Comments
 (0)