diff --git a/lib/postscript/request.ex b/lib/postscript/request.ex index 3060d6e..debcd42 100644 --- a/lib/postscript/request.ex +++ b/lib/postscript/request.ex @@ -45,37 +45,10 @@ defmodule Postscript.Request do request |> config.http_client.send(config.http_client_opts) - |> maybe_validate_json_decode(config) |> retry(request, config) |> finish(config) end - defp maybe_validate_json_decode({:ok, %{body: body, headers: headers}} = response, config) do - headers - |> Enum.reduce(%{}, fn {k, v}, acc -> Map.put(acc, String.downcase(k), v) end) - |> case do - %{"content-type" => "application/json"} -> - case config.json_codec.decode(body) do - {:ok, _decoded} -> - response - - {:error, decode_error} -> - Logger.warning([ - inspect(__MODULE__), - " received an invalid JSON response ", - inspect(body) - ]) - - {:error, decode_error} - end - - _otherwise -> - response - end - end - - defp maybe_validate_json_decode(response, _config), do: response - defp retry(response, _request, %_{retry: retry}) when is_nil(retry) or retry == false do response end diff --git a/test/postscript_test.exs b/test/postscript_test.exs index 81ab4cf..e93e04d 100644 --- a/test/postscript_test.exs +++ b/test/postscript_test.exs @@ -9,12 +9,6 @@ defmodule PostscriptTest do @not_ok_resp %{body: "{\"ok\":false}", headers: [], status_code: 400} - @not_json_resp %{ - body: "not json", - headers: [{"content-type", "application/json"}], - status_code: 200 - } - test "sends the proper HTTP method" do Http.Mock.start_link() @@ -166,26 +160,6 @@ defmodule PostscriptTest do assert {:error, %Response{}} = result end - test "logs warning and returns :error when response is not valid JSON" do - Http.Mock.start_link() - - response = {:ok, @not_json_resp} - - Http.Mock.put_response(response) - - operation = %Operation{method: :post, params: [hello: "world"], path: "/fake"} - - assert {result, log} = - with_log([level: :warning], fn -> - Postscript.request(operation, http_client: Http.Mock) - end) - - assert {:error, _error} = result - - assert log =~ "invalid JSON response" - assert log =~ "\"not json\"" - end - test "passes the response through when unrecognized" do Http.Mock.start_link()