@@ -5,6 +5,8 @@ defmodule Ethereumex.HttpClient do
5
5
6
6
alias Ethereumex.Config
7
7
8
+ require Logger
9
+
8
10
@ type empty_response :: :empty_response
9
11
@ type invalid_json :: { :invalid_json , any ( ) }
10
12
@ type http_client_error :: { :error , empty_response ( ) | invalid_json ( ) | any ( ) }
@@ -24,9 +26,23 @@ defmodule Ethereumex.HttpClient do
24
26
25
27
case Finch . request ( request , Ethereumex.Finch , Config . http_options ( ) ) do
26
28
{ :ok , % Finch.Response { body: body , status: code } } ->
27
- decode_body ( body , code , format_batch )
29
+ case decode_body ( body , code , format_batch ) do
30
+ { :ok , _response } = result ->
31
+ result
32
+
33
+ error ->
34
+ maybe_log_error (
35
+ "[#{ __MODULE__ } ] Decode failed, body - #{ inspect ( body ) } , payload - #{ inspect ( payload ) } , error - #{ inspect ( error ) } "
36
+ )
37
+
38
+ error
39
+ end
28
40
29
41
{ :error , error } ->
42
+ maybe_log_error (
43
+ "[#{ __MODULE__ } ] Request failed, payload - #{ inspect ( payload ) } , error - #{ inspect ( error ) } "
44
+ )
45
+
30
46
{ :error , error }
31
47
end
32
48
end
@@ -63,4 +79,12 @@ defmodule Ethereumex.HttpClient do
63
79
defp maybe_format_batch ( responses , true ) , do: format_batch ( responses )
64
80
65
81
defp maybe_format_batch ( responses , _ ) , do: responses
82
+
83
+ defp maybe_log_error ( message ) do
84
+ if Config . enable_request_error_logs ( ) do
85
+ Logger . error ( message )
86
+ else
87
+ :ok
88
+ end
89
+ end
66
90
end
0 commit comments