init commit
This commit is contained in:
28
lib/workload_service_web/controllers/fallback_controller.ex
Normal file
28
lib/workload_service_web/controllers/fallback_controller.ex
Normal file
@@ -0,0 +1,28 @@
|
||||
defmodule WorkloadServiceWeb.FallbackController do
|
||||
use WorkloadServiceWeb, :controller
|
||||
|
||||
def call(conn, {:error, :not_found}) do
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> put_view(json: WorkloadServiceWeb.ErrorJSON)
|
||||
|> render(:"404")
|
||||
end
|
||||
|
||||
def call(conn, {:error, reason}) when is_atom(reason) do
|
||||
conn
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> json(%{error: Atom.to_string(reason)})
|
||||
end
|
||||
|
||||
def call(conn, {:error, %{errors: errors}}) do
|
||||
conn
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> json(%{errors: errors})
|
||||
end
|
||||
|
||||
def call(conn, {:error, reason}) do
|
||||
conn
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> json(%{error: inspect(reason)})
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user