Handling Controller Errors
Return Status
Complete list of status code
https://hexdocs.pm/plug/Plug.Conn.Status.html
# 401 Unauthorized
send_resp(conn, 401, '')
send_resp(conn, :unauthorized, '') # same as aboveIf an error is raised during controller, its a 500
Development Errors
Phoenix auto creates a nice html page for raise errors in dev
dev.exs
config :react_phoenix, ReactPhoenixWeb.Endpoint,
http: [port: 4000],
debug_errors: false, #to disable for api endpointsIn prod, ErrorView will be used. Ecto.NoResultsError in ecto will be translated to 404, but everything else is usually a 500.
If you return a non conn, will be 500 orrr
Is not triggered when an error is raised, only when conn returns an error like in a with statement
Transforms nonconn response to valid conn response
If with fails, it just returns the unmatched value which probably has{:error, ....} in it. So in fallback controller
ErrorView
Last updated