Replace inspect(reason) with friendly error messages

Closes #81
This commit is contained in:
Claudio Ortolina
2026-03-05 20:25:13 +00:00
parent e8f393c5a0
commit 08f7565d44
18 changed files with 542 additions and 64 deletions
+17 -4
View File
@@ -6,6 +6,7 @@ defmodule MusicLibraryWeb.ArtistLive.Form do
alias MusicLibrary.Artists
alias MusicLibrary.Assets
alias MusicLibrary.Assets.Image
alias MusicLibraryWeb.ErrorMessages
@impl true
def mount(socket) do
@@ -249,14 +250,20 @@ defmodule MusicLibraryWeb.ArtistLive.Form do
def handle_async(:image_search, {:ok, {:error, reason}}, socket) do
{:noreply,
socket
|> assign(:image_search_error, "Search failed: #{inspect(reason)}")
|> assign(
:image_search_error,
gettext("Search failed") <> ": " <> ErrorMessages.friendly_message(reason)
)
|> assign(:image_search_loading, false)}
end
def handle_async(:image_search, {:exit, reason}, socket) do
{:noreply,
socket
|> assign(:image_search_error, "Search failed: #{inspect(reason)}")
|> assign(
:image_search_error,
gettext("Search failed") <> ": " <> ErrorMessages.friendly_message(reason)
)
|> assign(:image_search_loading, false)}
end
@@ -283,14 +290,20 @@ defmodule MusicLibraryWeb.ArtistLive.Form do
def handle_async(:image_download, {:ok, {:error, reason}}, socket) do
{:noreply,
socket
|> assign(:image_search_error, "Download failed: #{inspect(reason)}")
|> assign(
:image_search_error,
gettext("Download failed") <> ": " <> ErrorMessages.friendly_message(reason)
)
|> assign(:image_search_loading, false)}
end
def handle_async(:image_download, {:exit, reason}, socket) do
{:noreply,
socket
|> assign(:image_search_error, "Download failed: #{inspect(reason)}")
|> assign(
:image_search_error,
gettext("Download failed") <> ": " <> ErrorMessages.friendly_message(reason)
)
|> assign(:image_search_loading, false)}
end
+10 -5
View File
@@ -6,6 +6,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
alias MusicLibrary.{Artists, Records}
alias MusicLibrary.Artists.ArtistInfo
alias MusicLibraryWeb.ErrorMessages
attr :country, :map, required: true
@@ -544,7 +545,8 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
socket
|> put_toast(
:error,
gettext("Error refreshing artist info") <> "," <> inspect(reason)
gettext("Error refreshing artist info") <>
": " <> ErrorMessages.friendly_message(reason)
)}
end
end
@@ -563,7 +565,8 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
socket
|> put_toast(
:error,
gettext("Error refreshing Wikipedia data") <> "," <> inspect(reason)
gettext("Error refreshing Wikipedia data") <>
": " <> ErrorMessages.friendly_message(reason)
)}
end
end
@@ -585,7 +588,8 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
socket
|> put_toast(
:error,
gettext("Error refreshing Last.fm data") <> "," <> inspect(reason)
gettext("Error refreshing Last.fm data") <>
": " <> ErrorMessages.friendly_message(reason)
)}
end
end
@@ -603,7 +607,8 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
socket
|> put_toast(
:error,
gettext("Error refreshing artist image") <> "," <> inspect(reason)
gettext("Error refreshing artist image") <>
": " <> ErrorMessages.friendly_message(reason)
)}
end
end
@@ -624,7 +629,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
socket
|> put_toast(
:error,
gettext("Error importing record") <> "," <> inspect(changeset.errors)
gettext("Error importing record") <> ": " <> ErrorMessages.friendly_message(changeset)
)}
end
end