Skip to content

Commit 7ce49d4

Browse files
authored
fix: add error handling for bad rpc connection (#476)
1 parent 01fd4ce commit 7ce49d4

File tree

1 file changed

+23
-3
lines changed
  • explorer/lib/explorer_web/live/pages/home

1 file changed

+23
-3
lines changed

explorer/lib/explorer_web/live/pages/home/index.ex

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ defmodule ExplorerWeb.Home.Index do
2424

2525
operators_registered = get_operators_registered()
2626

27-
latest_batches = Batches.get_latest_batches(%{amount: 5})
28-
|> Enum.map(fn %Batches{merkle_root: merkle_root} -> merkle_root end) #extract only the merkle root
27+
latest_batches =
28+
Batches.get_latest_batches(%{amount: 5})
29+
# extract only the merkle root
30+
|> Enum.map(fn %Batches{merkle_root: merkle_root} -> merkle_root end)
2931

3032
verified_proofs = Batches.get_amount_of_verified_proofs()
3133

@@ -56,8 +58,26 @@ defmodule ExplorerWeb.Home.Index do
5658
IO.puts("Other transport error: #{inspect(e)}")
5759
end
5860

61+
e in FunctionClauseError ->
62+
case e do
63+
%FunctionClauseError{
64+
module: ExplorerWeb.Home.Index
65+
} ->
66+
{
67+
:ok,
68+
assign(socket,
69+
verified_batches: :empty,
70+
operators_registered: :empty,
71+
latest_batches: :empty,
72+
verified_proofs: :empty
73+
)
74+
|> put_flash(:error, "Something went wrong with the RPC, please try again later.")
75+
}
76+
end
77+
5978
e ->
60-
raise e
79+
Logger.error("Other error: #{inspect(e)}")
80+
{:ok, socket |> put_flash(:error, "Something went wrong, please try again later.")}
6181
end
6282

6383
# tail-call recursion

0 commit comments

Comments
 (0)