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 11, 2024
1 parent 4e702a0 commit f66411e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 5 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,9 @@ defmodule Core.Clients.Hydra do

defp conf(key), do: Application.get_env(:core, __MODULE__)[key]

defp hydra_error({:error, _}), do: "internal network error"
defp hydra_error({:ok, %HTTPoison.Response{status_code: code, body: body}}),
do: "hydra error: code=#{code}, body=#{body}"

defp headers(), do: [{"accept", "application/json"}, {"content-type", "application/json"}]
end
3 changes: 2 additions & 1 deletion apps/core/test/services/cloud/workflow_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Core.Services.Cloud.WorkflowTest do
use Core.SchemaCase, async: true
use Core.SchemaCase, async: false
use Mimic
alias Core.Clients.Console
alias Core.Services.{Cloud, Cloud.Workflow}
Expand Down Expand Up @@ -28,6 +28,7 @@ defmodule Core.Services.Cloud.WorkflowTest do
expect(Req, :post, fn _, [graphql: {_, %{clusterId: ^cluster_id}}] ->
{:ok, %Req.Response{status: 200, body: %{"data" => %{"createServiceDeployment" => %{"id" => Ecto.UUID.generate()}}}}}
end)
expect(DNS, :resolve, fn _ -> {:ok, ['some-ip']} end)

{:ok, %{external_id: svc_id} = instance} = Workflow.provision(instance)

Expand Down
1 change: 1 addition & 0 deletions apps/core/test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Mimic.copy(Core.Buffers.TokenAudit)
Mimic.copy(Core.Clients.Hydra)
Mimic.copy(Cloudflare.DnsRecord)
Mimic.copy(Kazan)
Mimic.copy(DNS)
Mimic.copy(Goth.Token)
Mimic.copy(GoogleApi.CloudBilling.V1.Api.Projects)
Mimic.copy(GoogleApi.CloudResourceManager.V3.Api.Projects)
Expand Down

0 comments on commit f66411e

Please sign in to comment.