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
This commit is contained in:
parent
2695e8a0eb
commit
8db9fb4fcd
1 changed files with 17 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue