From 9a5075335ef4692968166040f7ddc00e562cbe20 Mon Sep 17 00:00:00 2001 From: Mario Uher Date: Fri, 29 Dec 2023 16:27:21 +0100 Subject: [PATCH 1/2] Improve logging of auth issues --- lib/mix/tasks/hex.organization.ex | 5 +++++ test/mix/tasks/hex.organization_test.exs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/mix/tasks/hex.organization.ex b/lib/mix/tasks/hex.organization.ex index d332bd2d..295feb42 100644 --- a/lib/mix/tasks/hex.organization.ex +++ b/lib/mix/tasks/hex.organization.ex @@ -272,6 +272,11 @@ defmodule Mix.Tasks.Hex.Organization do {:ok, {code, _body, _}} when code in 200..299 -> :ok + {:ok, {code, %{"message" => message}, _}} when code in [401, 403] -> + Hex.Shell.error( + "Failed to authenticate against organization repository with given key because of: #{message}" + ) + {:ok, {code, _body, _}} when code in [401, 403] -> Hex.Shell.error("Failed to authenticate against organization repository with given key") diff --git a/test/mix/tasks/hex.organization_test.exs b/test/mix/tasks/hex.organization_test.exs index 933ae836..8fd0c393 100644 --- a/test/mix/tasks/hex.organization_test.exs +++ b/test/mix/tasks/hex.organization_test.exs @@ -90,7 +90,9 @@ defmodule Mix.Tasks.Hex.OrganizationTest do Mix.Tasks.Hex.Organization.run(["auth", "myorg", "--key", "mykey"]) assert_received {:mix_shell, :error, - ["Failed to authenticate against organization repository with given key"]} + [ + "Failed to authenticate against organization repository with given key because of: invalid API key" + ]} end) end From 56570d770f3b4d54aa714a0a125e2fd65d7081cb Mon Sep 17 00:00:00 2001 From: Mario Uher Date: Sat, 30 Dec 2023 12:03:31 +0100 Subject: [PATCH 2/2] Remove redundant case clause --- lib/mix/tasks/hex.organization.ex | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/mix/tasks/hex.organization.ex b/lib/mix/tasks/hex.organization.ex index 295feb42..c855b366 100644 --- a/lib/mix/tasks/hex.organization.ex +++ b/lib/mix/tasks/hex.organization.ex @@ -277,9 +277,6 @@ defmodule Mix.Tasks.Hex.Organization do "Failed to authenticate against organization repository with given key because of: #{message}" ) - {:ok, {code, _body, _}} when code in [401, 403] -> - Hex.Shell.error("Failed to authenticate against organization repository with given key") - other -> Hex.Utils.print_error_result(other) Hex.Shell.error("Failed to verify authentication key")