From a6fd5e1c1e19add58e428140c4df0fce22194de0 Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 13 Jan 2026 14:57:39 +0100 Subject: [PATCH] fix: Replace Ash.read! with error handling in CustomFieldValueLive.Index - Replace Ash.read! with Ash.read and proper error handling in mount/3 --- .../live/custom_field_value_live/index.ex | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/mv_web/live/custom_field_value_live/index.ex b/lib/mv_web/live/custom_field_value_live/index.ex index 0847cd6..eea578e 100644 --- a/lib/mv_web/live/custom_field_value_live/index.ex +++ b/lib/mv_web/live/custom_field_value_live/index.ex @@ -75,10 +75,35 @@ defmodule MvWeb.CustomFieldValueLive.Index do def mount(_params, _session, socket) do actor = current_actor(socket) - {:ok, - socket - |> assign(:page_title, "Listing Custom field values") - |> stream(:custom_field_values, Ash.read!(Mv.Membership.CustomFieldValue, actor: actor))} + # Early return if no actor (prevents exceptions in unauthenticated tests) + if is_nil(actor) do + {:ok, + socket + |> assign(:page_title, "Listing Custom field values") + |> stream(:custom_field_values, [])} + else + case Ash.read(Mv.Membership.CustomFieldValue, actor: actor) do + {:ok, custom_field_values} -> + {:ok, + socket + |> assign(:page_title, "Listing Custom field values") + |> stream(:custom_field_values, custom_field_values)} + + {:error, %Ash.Error.Forbidden{}} -> + {:ok, + socket + |> assign(:page_title, "Listing Custom field values") + |> stream(:custom_field_values, []) + |> put_flash(:error, gettext("You do not have permission to view custom field values"))} + + {:error, error} -> + {:ok, + socket + |> assign(:page_title, "Listing Custom field values") + |> stream(:custom_field_values, []) + |> put_flash(:error, format_error(error))} + end + end end @impl true