From 8db9fb4fcd594b6ebfbbb0dd159811c685a12290 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 11 May 2026 15:25:34 -0500 Subject: [PATCH] fix(gaiia): add error handling and logging for model fetch - Handle empty manufacturer_id selection (select placeholder) - Log and flash when model fetch fails or returns empty - Add require Logger to reconciliation live view --- .../live/org/gaiia_reconciliation_live.ex | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/towerops_web/live/org/gaiia_reconciliation_live.ex b/lib/towerops_web/live/org/gaiia_reconciliation_live.ex index 44e3e353..6a10f6f6 100644 --- a/lib/towerops_web/live/org/gaiia_reconciliation_live.ex +++ b/lib/towerops_web/live/org/gaiia_reconciliation_live.ex @@ -6,6 +6,8 @@ defmodule ToweropsWeb.Org.GaiiaReconciliationLive do alias Towerops.Gaiia.InventoryCreator alias Towerops.Gaiia.Reconciliation + require Logger + @impl true def mount(_params, _session, socket) do org = socket.assigns.current_scope.organization @@ -66,6 +68,10 @@ defmodule ToweropsWeb.Org.GaiiaReconciliationLive do |> assign(:selected_manufacturer, nil)} end + def handle_event("select_manufacturer", %{"manufacturer_id" => ""}, socket) do + {:noreply, assign(socket, :selected_manufacturer, nil)} + end + def handle_event("select_manufacturer", %{"manufacturer_id" => manufacturer_id}, socket) do org_id = socket.assigns.organization.id existing = socket.assigns.models @@ -75,13 +81,22 @@ defmodule ToweropsWeb.Org.GaiiaReconciliationLive do assign(socket, :selected_manufacturer, manufacturer_id) else case InventoryCreator.list_models(org_id, manufacturer_id) do + {:ok, []} -> + Logger.warning("Gaiia: no models for manufacturer #{manufacturer_id}") + + socket + |> assign(:selected_manufacturer, manufacturer_id) + |> put_flash(:warning, t("No models found for this manufacturer.")) + {:ok, models} -> socket |> assign(:models, Map.put(existing, manufacturer_id, models)) |> assign(:selected_manufacturer, manufacturer_id) - {:error, _} -> - socket + {:error, reason} -> + Logger.error("Gaiia: failed to fetch models: #{inspect(reason)}") + + put_flash(socket, :error, t("Failed to load models. Check server logs.")) end end