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 rendered yourapp.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 set debug_errors: false in config/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

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -