@@ -2,6 +2,7 @@ defmodule MusicLibraryWeb.LastFmController do
|
|||||||
use MusicLibraryWeb, :controller
|
use MusicLibraryWeb, :controller
|
||||||
|
|
||||||
alias MusicLibrary.Secrets
|
alias MusicLibrary.Secrets
|
||||||
|
alias MusicLibraryWeb.ErrorMessages
|
||||||
|
|
||||||
def callback(conn, %{"token" => token}) do
|
def callback(conn, %{"token" => token}) do
|
||||||
with {:ok, session} <- LastFm.get_session(token),
|
with {:ok, session} <- LastFm.get_session(token),
|
||||||
@@ -12,7 +13,11 @@ defmodule MusicLibraryWeb.LastFmController do
|
|||||||
else
|
else
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
conn
|
conn
|
||||||
|> put_toast(:error, "Failed to connect your Last.fm account: #{reason}")
|
|> put_toast(
|
||||||
|
:error,
|
||||||
|
gettext("Failed to connect your Last.fm account") <>
|
||||||
|
": " <> ErrorMessages.friendly_message(reason)
|
||||||
|
)
|
||||||
|> redirect(to: ~p"/")
|
|> redirect(to: ~p"/")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2380,3 +2380,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "the cover image asset was not found"
|
msgid "the cover image asset was not found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/controllers/last_fm_controller.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Failed to connect your Last.fm account"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -2380,3 +2380,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "the cover image asset was not found"
|
msgid "the cover image asset was not found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/controllers/last_fm_controller.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Failed to connect your Last.fm account"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ defmodule MusicLibraryWeb.LastFmControllerTest do
|
|||||||
|
|
||||||
@tag :logged_out
|
@tag :logged_out
|
||||||
@tag :capture_log
|
@tag :capture_log
|
||||||
test "on error, redirects with error flash", %{conn: conn} do
|
test "on error, redirects with friendly error flash", %{conn: conn} do
|
||||||
error_json = %{
|
error_json = %{
|
||||||
"error" => 4,
|
"error" => 4,
|
||||||
"message" => "Invalid authentication token"
|
"message" => "Invalid authentication token"
|
||||||
@@ -40,7 +40,9 @@ defmodule MusicLibraryWeb.LastFmControllerTest do
|
|||||||
conn = get(conn, ~p"/auth/last_fm/callback", %{"token" => "bad-token"})
|
conn = get(conn, ~p"/auth/last_fm/callback", %{"token" => "bad-token"})
|
||||||
|
|
||||||
assert redirected_to(conn) == "/"
|
assert redirected_to(conn) == "/"
|
||||||
assert conn.assigns.flash["error"] =~ "Failed to connect"
|
|
||||||
|
assert conn.assigns.flash["error"] ==
|
||||||
|
"Failed to connect your Last.fm account: Last.fm authentication failed"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user