Ash FrameworkAF
Ash Framework3y ago
14 replies
Robert Graff

Handling an %Ash.Error.Invalid{} in LiveView

Sorry for the noob question, but the AshPhoenix guide doesn't show any error handling.

This is the code that I assumed would work, but update returns a {:error, %Ash.Error.Invalid{} } How do I get those errors onto the form?

  def handle_event("update-slug", params, socket) do
    current_account = socket.assigns.current_account

    case Account.update(current_account, params, actor: socket.assigns.current_user) do
      {:ok, applied_account} ->
        info = "Slug changed successfully."

        socket =
          socket
          |> put_flash(:info, info)
          |> assign(:current_account, applied_account)
          |> push_navigate(to: ~p"/#{applied_account.slug}/settings")

        {:noreply, socket}

      {:error, slug_form} ->
        {:noreply, assign(socket, :slug_form, slug_form)}
    end
  end
Was this page helpful?