I am trying to get the generated FallbackController working with a function which is not a classical “action” but It just won’t work. No I am wondering: Is this even intended?
This is what I do:
defmodule ApiWeb.AuthController do
use ApiWeb, :controller
plug(Ueberauth)
alias Api.Accounts
alias Api.Accounts.User
action_fallback(ApiWeb.FallbackController)
....
# The return of this function should trigger the FallbackController if an error occurs.
def register_user(conn, :identity, auth) do
with {:ok, result} <- Accounts.create_user(:identity, auth) do
# Encode a JWT
{:ok, jwt, _} = Api.Guardian.encode_and_sign(result.user)
# Return token to client
conn
|> put_status(:created)
|> put_resp_header("authorization", "Bearer #{jwt}")
|> json(%{access_token: jwt})
end
end
...
In my FallbackController I added this call function:
def call(conn, {:error, :identity_representation, changeset, _}) do
conn
|> put_status(:unprocessable_entity)
|> render(ApiWeb.ChangesetView, "error.json-api", changeset: changeset)
end
But the call never gets called. Is there some way to use the FallbackController with some conventional function?