fix: Replace Ash.read! with error handling in CustomFieldValueLive.Index
- Replace Ash.read! with Ash.read and proper error handling in mount/3
This commit is contained in:
parent
807e03d86b
commit
fba0ea5ec0
1 changed files with 29 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue