diff --git a/lib/nerves_hub_web/live/firmware.ex b/lib/nerves_hub_web/live/firmware.ex index 3e9b0907a..903f982ad 100644 --- a/lib/nerves_hub_web/live/firmware.ex +++ b/lib/nerves_hub_web/live/firmware.ex @@ -140,6 +140,16 @@ defmodule NervesHubWeb.Live.Firmware do }} -> error_feedback(socket, "No matching product could be found.") + {:error, + %Ecto.Changeset{ + errors: [ + uuid: + {"has already been taken", + [constraint: :unique, constraint_name: "firmwares_product_id_uuid_index"]} + ] + } = changeset} -> + error_feedback(socket, changeset) + {:error, %Ecto.Changeset{}} -> error_feedback(socket, "Unknown error uploading firmware.") @@ -151,6 +161,20 @@ defmodule NervesHubWeb.Live.Firmware do end end + defp error_feedback( + socket, + %Ecto.Changeset{errors: [uuid: {"has already been taken", _}]} = changeset + ) do + socket + |> assign(:error_message, "Duplicate Firmware Is Not Allowed") + |> assign(:error_code, :duplicate_firmware) + |> assign( + :firmware_path, + "/org/#{socket.assigns.org.name}/#{socket.assigns.product.name}/firmware/#{changeset.changes.uuid}" + ) + |> noreply() + end + defp error_feedback(socket, %Ecto.Changeset{} = changeset) do error_message = changeset.errors diff --git a/lib/nerves_hub_web/live/firmware_templates/upload_firmware_template.html.heex b/lib/nerves_hub_web/live/firmware_templates/upload_firmware_template.html.heex index fa8898276..ed6f3b21e 100644 --- a/lib/nerves_hub_web/live/firmware_templates/upload_firmware_template.html.heex +++ b/lib/nerves_hub_web/live/firmware_templates/upload_firmware_template.html.heex @@ -9,7 +9,14 @@ <.live_file_input upload={@uploads.firmware} required />
- <%= @error_message %> + + <%= case @error_code do %> + <% :duplicate_firmware -> %> + <%= @error_message %> View Firmware + <% _ -> %> + <%= @error_message %> + <% end %> +