I have multiple controller methods, where I am pattern matching with the coming parameters one of them is
def index(conn, %{
"id" => camera_exid,
"from" => from,
"to" => to,
"limit" => "3600",
"page" => _page
}) do
when user requests such as http://localhost:4000/v2/cameras/pocri-yweod/recordings/snapshots?limit=3600&page=1
it throws an error, and of course, it supposes to through error, but is there any way to handle such error more gracefully than an exception? without creating another index with fewer values to pattern match?
I tried creating a fallback controller very basic
defmodule EvercamMediaWeb.FallbackController do
use EvercamMediaWeb, :controller
def call(conn, what) do
IO.inspect(what)
render_error(conn, 400, "error.")
end
end
but it didn't work.
Is it possible to make it for the whole controller? when the pattern matched parameters doesn't match, it returns 400 while saying which params are missing? I am the only pattern matching those parameters in the head which are definite.
def index(conn, incomplete), do: render_error ...
. – Aleksei Matiushkin