Skip to content

Commit

Permalink
fix: handle new response from chromedriver
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Jun 7, 2024
1 parent 0e0aeff commit 4f82ca8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/wallaby/httpclient.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule Wallaby.HTTPClient do
defp make_request(method, url, body, retry_count, retry_reasons) do
method
|> HTTPoison.request(url, body, headers(), request_opts())
|> handle_response
|> handle_response()
|> case do
{:error, :httpoison, error} ->
:timer.sleep(jitter())
Expand Down Expand Up @@ -102,8 +102,9 @@ defmodule Wallaby.HTTPClient do
{:ok, response}
| {:error, web_driver_error_reason}
| no_return
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
defp check_for_response_errors(response) do
response = coerce_json_message(response)

case Map.get(response, "value") do
%{"class" => "org.openqa.selenium.StaleElementReferenceException"} ->
{:error, :stale_reference}
Expand All @@ -120,6 +121,9 @@ defmodule Wallaby.HTTPClient do
} ->
{:error, :stale_reference}

%{"message" => %{"value" => "An invalid or illegal selector was specified"}} ->
{:error, :invalid_selector}

%{"message" => "invalid selector" <> _} ->
{:error, :invalid_selector}

Expand Down Expand Up @@ -158,4 +162,24 @@ defmodule Wallaby.HTTPClient do
end

defp jitter, do: :rand.uniform(@max_jitter)

defp coerce_json_message(%{"value" => %{"message" => message} = value} = response) do
value =
case Regex.named_captures(~r/(?<type>.*): (?<payload>{.*})\n.*/, message) do
%{"payload" => payload, "type" => type} ->
%{
"message" => Jason.decode!(payload),
"type" => type
}

_ ->
value
end

put_in(response["value"], value)
end

defp coerce_json_message(response) do
response
end
end

0 comments on commit 4f82ca8

Please sign in to comment.