Skip to content

Commit

Permalink
Improve hydra error messages
Browse files Browse the repository at this point in the history
This will bubble hydra errors to users whihc might make it easier to understand misconfigurations
  • Loading branch information
michaeljguarino committed Oct 10, 2024
1 parent 4e702a0 commit 5fef18b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/core/lib/core/clients/hydra.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 5fef18b

Please sign in to comment.