elixir - Setting up custom response for exception in Phoenix Application -
im writing phoenix application ecto , have following snippet in test
{:ok, data} = poison.encode(%{email: "nonexisting@user.com", password: "mypass"}) conn() |> put_req_header("content-type", "application/json") |> put_req_header("accept", "application/json") |> post(session_path(@endpoint, :create), data) > json_response(:not_found) == %{}
this throws ecto.noresultserror
i have defined
defimpl plug.exception, for: ecto.noresultserror def status(_exception), do: 404 end
but test still throws ecto.noresultserror, pointers?
let's consider how works per environment.
in
:prod
, default render error pages, should see page renderedyourapp.errorview
status code;in
:dev
, default show debug pages, because majority of times have error while building code. if want see rendered error page, need setdebug_errors: false
inconfig/dev.exs
;in
:test
, works production but, because calling application test, test crash if application crashes. improving on future versions, should able write like:assert_raise ecto.noresultserror, fn -> conn, "/foo" end {status, headers, body} = sent_response(conn) assert status == 404 assert body =~ "oops"
Comments
Post a Comment