check fetched metadata in multiple places

pull/2900/head
Ayrat Badykov 5 years ago
parent cd27d9e09a
commit 56f07bb85e
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 16
      apps/explorer/lib/explorer/token/instance_metadata_retriever.ex

@ -80,7 +80,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
def fetch_json(%{"tokenURI" => {:ok, [json]}}) do
{:ok, json} = decode_json(json)
{:ok, %{metadata: json}}
check_type(json)
rescue
e ->
Logger.debug(["Unknown metadata format #{inspect(json)}. error #{inspect(e)}"],
@ -101,11 +101,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
{:ok, %Response{body: body, status_code: 200}} ->
{:ok, json} = decode_json(body)
if is_map(json) do
{:ok, %{metadata: json}}
else
{:error, :wrong_metadata_type}
end
check_type(json)
{:ok, %Response{body: body}} ->
{:error, body}
@ -131,4 +127,12 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
|> Jason.decode()
end
end
defp check_type(json) when is_map(json) do
{:ok, %{metadata: json}}
end
defp check_type(_) do
{:error, :wrong_metadata_type}
end
end

Loading…
Cancel
Save