Skip to content

Commit

Permalink
Provide more descriptive error message when JSX fails to decode
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
On branch aws-support - Mon 25 Sep 2017 13:51:00 PDT by Geoff Lee <[email protected]>
  • Loading branch information
geoff-lee-lendesk committed Sep 25, 2017
1 parent 20f103e commit 441a9dd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/tirexs/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,13 @@ defmodule Tirexs.HTTP do

@doc false
def decode(json, opts \\ [{:labels, :atom}]) do
JSX.decode!(IO.iodata_to_binary(json), opts)
with binary <- IO.iodata_to_binary(json),
{:ok, decoded_json} <- JSX.decode(binary, opts) do
decoded_json
else
{:error, msg} ->
raise "Response is invalid JSON. Response: \"#{json}\". JSX Error: \"#{msg}\""
end
end

defp __merge__(map1, map2) do
Expand Down

0 comments on commit 441a9dd

Please sign in to comment.