Add clause for 404 response from CoinGecko

pull/5671/head
Никита Поздняков 2 years ago
parent ff3033e851
commit 245cd61aa1
No known key found for this signature in database
GPG Key ID: F344106F9804FE5F
  1. 12
      apps/explorer/lib/explorer/chain/cache/token_exchange_rate.ex

@ -61,7 +61,7 @@ defmodule Explorer.Chain.Cache.TokenExchangeRate do
|> cache_key()
|> fetch_from_cache()
if is_nil(cached_value) || Decimal.cmp(cached_value, 0) == :eq do
if is_nil(cached_value) || cached_value == :not_found_coingecko || Decimal.cmp(cached_value, 0) == :eq do
fetch_from_db(token_hash)
else
cached_value
@ -82,7 +82,7 @@ defmodule Explorer.Chain.Cache.TokenExchangeRate do
|> cache_key()
|> fetch_from_cache()
if is_nil(cached_value) || Decimal.cmp(cached_value, 0) == :eq do
if is_nil(cached_value) || cached_value == :not_found_coingecko || Decimal.cmp(cached_value, 0) == :eq do
fetch_from_db(token_hash)
else
cached_value
@ -134,6 +134,9 @@ defmodule Explorer.Chain.Cache.TokenExchangeRate do
{:ok, [rates]} ->
rates.usd_value
{:error, "Could not find coin with the given id"} ->
:not_found_coingecko
_ ->
nil
end
@ -144,6 +147,9 @@ defmodule Explorer.Chain.Cache.TokenExchangeRate do
{:ok, [rates]} ->
rates.usd_value
{:error, "Could not find coin with the given id"} ->
:not_found_coingecko
_ ->
nil
end
@ -174,7 +180,7 @@ defmodule Explorer.Chain.Cache.TokenExchangeRate do
def put_into_db(token_hash, exchange_rate) do
token = get_token(token_hash)
if token && !is_nil(exchange_rate) do
if token && !is_nil(exchange_rate) && exchange_rate != :not_found_coingecko do
token
|> Changeset.change(%{exchange_rate: exchange_rate})
|> Repo.update()

Loading…
Cancel
Save