Handle smart contracts read errors

catchup-block-interval-env
Nikita Pozdniakov 2 years ago committed by Viktor Baranov
parent 7c038dad05
commit 4189362e0f
  1. 2
      apps/block_scout_web/lib/block_scout_web/templates/smart_contract/_function_response.html.eex
  2. 2
      apps/block_scout_web/lib/block_scout_web/templates/smart_contract/_functions.html.eex
  3. 11
      apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex
  4. 1
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex
  5. 2
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/decode_error.ex

@ -32,7 +32,7 @@
<% {:error, %{code: code, message: message}} -> %> <% {:error, %{code: code, message: message}} -> %>
<pre><div style="padding-left: 20px">(error) : <%= "(#{code}) #{message}" %></div></pre> <pre><div style="padding-left: 20px">(error) : <%= "(#{code}) #{message}" %></div></pre>
<% {:error, error} -> %> <% {:error, error} -> %>
<pre><div style="padding-left: 20px">(error) : <%= error %></div></pre> <pre><div style="padding-left: 20px">(error) : <%= cut_rpc_url(error) %></div></pre>
<% _ -> %> <% _ -> %>
<pre> <pre>
[<%= for {item, index} <- Enum.with_index(@outputs) do %> [<%= for {item, index} <- Enum.with_index(@outputs) do %>

@ -152,7 +152,7 @@
</div> </div>
<% error?(function["outputs"]) -> %> <% error?(function["outputs"]) -> %>
<% {:error, text_error} = function["outputs"] %> <% {:error, text_error} = function["outputs"] %>
<div class="alert alert-danger py-2 word-break-all" style="margin-bottom: 0;"><%= text_error %></div> <div class="alert alert-danger py-2 word-break-all" style="margin-bottom: 0;"><%= cut_rpc_url(text_error) %></div>
<% true -> %> <% true -> %>
<% nil %> <% nil %>
<% end %> <% end %>

@ -285,4 +285,15 @@ defmodule BlockScoutWeb.SmartContractView do
end end
def not_last_element?(length, index), do: length > 1 and index < length - 1 def not_last_element?(length, index), do: length > 1 and index < length - 1
def cut_rpc_url(error) do
transport_options = Application.get_env(:explorer, :json_rpc_named_arguments)[:transport_options]
error
|> String.replace(transport_options[:url], "rpc_url")
|> (&if(transport_options[:fallback_url],
do: String.replace(&1, transport_options[:fallback_url], "rpc_url"),
else: &1
)).()
end
end end

@ -56,6 +56,7 @@ defmodule EthereumJSONRPC.Contract do
|> case do |> case do
{:ok, responses} -> responses {:ok, responses} -> responses
{:error, {:bad_gateway, _request_url}} -> raise "Bad gateway" {:error, {:bad_gateway, _request_url}} -> raise "Bad gateway"
{:error, {reason, _request_url}} -> raise to_string(reason)
{:error, reason} when is_atom(reason) -> raise Atom.to_string(reason) {:error, reason} when is_atom(reason) -> raise Atom.to_string(reason)
{:error, error} -> raise error {:error, error} -> raise error
end end

@ -61,7 +61,7 @@ defmodule EthereumJSONRPC.DecodeError do
request: request:
url: #{if hide_url, do: "hidden", else: request_url} url: #{if hide_url, do: "rpc_url", else: request_url}
body: #{truncated_request_body} body: #{truncated_request_body}

Loading…
Cancel
Save