Hi! I want to understand Central Error Handling in Elixir/Phoenix.
I have learnt a bit about defexception
& using action_fallback FallbackController
. I want to understand the idiomatic practices for handling errors here.
Though I am not there yet, I will be using Phoenix Channels & Sockets extensively, while we are on this topic would also like to learn this.
I have tried googling quite a bit about it, if somebody can direct me to the right resources on this, that would be great. Thanks
1 Like
So I am facing a peculiar challenge using Plug.ErrorHandler
@impl Plug.ErrorHandler
def handle_errors(conn, %{reason: %Phoenix.Router.NoRouteError{message: message}}) do
conn
|> put_status(:not_found)
|> json(%{error: message})
|> halt()
end
I checked the conn struct
, Its properly setting the status, resp_body & all that but my test is receiving conn.status == nil
& not conn.status == 404
What am I missing here?
describe "delete user" do
test "error: deletes chosen user", %{conn: conn} do
conn = delete(conn, ~p"/api/v1/users/profile")
# FIXME: This is not working as expected
# assert conn.status == 404
assert conn.status == nil
end
end
Thanks
1 Like