From 5fef18bb227b77fc158592153450bbea95c4a712 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Thu, 10 Oct 2024 15:14:16 -0400 Subject: [PATCH] Improve hydra error messages This will bubble hydra errors to users whihc might make it easier to understand misconfigurations --- apps/core/lib/core/clients/hydra.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/core/lib/core/clients/hydra.ex b/apps/core/lib/core/clients/hydra.ex index d696a723c..9615ef797 100644 --- a/apps/core/lib/core/clients/hydra.ex +++ b/apps/core/lib/core/clients/hydra.ex @@ -129,7 +129,7 @@ defmodule Core.Clients.Hydra do do: {:ok, Poison.decode!(body, as: type)} defp handle_response(error, _) do Logger.error "Failed to call hydra: #{inspect(error)}" - {:error, :unauthorized} + {:error, hydra_error(error)} end defp user_details(user) do @@ -156,5 +156,10 @@ defmodule Core.Clients.Hydra do defp conf(key), do: Application.get_env(:core, __MODULE__)[key] + defp hydra_error({:error, _}), do: {:error, "internal network error"} + defp hydra_error({:ok, %HTTPoison.Response{status_code: code, body: body}}) do + {:error, "hydra error: code=#{code}, body=#{body}"} + end + defp headers(), do: [{"accept", "application/json"}, {"content-type", "application/json"}] end