5
5
"errors"
6
6
"fmt"
7
7
"math/big"
8
+ "net/url"
8
9
"strconv"
9
10
"strings"
10
11
"time"
@@ -51,6 +52,22 @@ type APIBackend struct {
51
52
sync SyncProgressBackend
52
53
}
53
54
55
+ type errorFilteredFallbackClient struct {
56
+ impl types.FallbackClient
57
+ url string
58
+ }
59
+
60
+ func (c * errorFilteredFallbackClient ) CallContext (ctx context.Context , result interface {}, method string , args ... interface {}) error {
61
+ err := c .impl .CallContext (ctx , result , method , args ... )
62
+ if err != nil && strings .Contains (err .Error (), c .url ) {
63
+ // avoids leaking the URL in the error message.
64
+ // URL can contain sensitive information such as API keys.
65
+ log .Warn ("fallback client error" , "error" , err )
66
+ return errors .New ("Failed to call fallback API" )
67
+ }
68
+ return err
69
+ }
70
+
54
71
type timeoutFallbackClient struct {
55
72
impl types.FallbackClient
56
73
timeout time.Duration
@@ -77,12 +94,22 @@ func CreateFallbackClient(fallbackClientUrl string, fallbackClientTimeout time.D
77
94
types .SetFallbackError (strings .Join (fields , ":" ), int (errNumber ))
78
95
return nil , nil
79
96
}
97
+
80
98
var fallbackClient types.FallbackClient
81
99
var err error
82
100
fallbackClient , err = rpc .Dial (fallbackClientUrl )
83
101
if err != nil {
84
102
return nil , fmt .Errorf ("failed creating fallback connection: %w" , err )
85
103
}
104
+ url , err := url .Parse (fallbackClientUrl )
105
+ if err != nil {
106
+ return nil , fmt .Errorf ("failed parsing fallback URL: %w" , err )
107
+ }
108
+ fallbackClient = & errorFilteredFallbackClient {
109
+ impl : fallbackClient ,
110
+ url : url .String (),
111
+ }
112
+
86
113
if fallbackClientTimeout != 0 {
87
114
fallbackClient = & timeoutFallbackClient {
88
115
impl : fallbackClient ,
0 commit comments