@@ -17,7 +17,7 @@ import (
17
17
"time"
18
18
)
19
19
20
- const rateLimitError = "429 Too Many Requests"
20
+ const TooManyRequestsErrorMessage = "429 Too Many Requests"
21
21
22
22
func updateTwitterCookies (config types.TradogeConfig ) {
23
23
scraper := twitterscraper .New ()
@@ -114,11 +114,11 @@ func searchTweets(scraper *twitterscraper.Scraper, query string, config types.Tr
114
114
log .Println ("Total tweets:" , counter )
115
115
}
116
116
117
- type TweeterConnectionError struct {
117
+ type ConnectionError struct {
118
118
Err error
119
119
}
120
120
121
- func (t * TweeterConnectionError ) Error () string {
121
+ func (t * ConnectionError ) Error () string {
122
122
return fmt .Sprintf ("Failed to connect to Twitter: %v" , t .Err )
123
123
}
124
124
@@ -140,10 +140,10 @@ func getLastMatchingTweet(scraper *twitterscraper.Scraper, query string) (*twitt
140
140
return & tweet .Tweet , nil
141
141
}
142
142
log .Printf ("Failed to get last tweet: %v" , tweet .Error )
143
- if strings .Contains (tweet .Error .Error (), rateLimitError ) {
143
+ if strings .Contains (tweet .Error .Error (), TooManyRequestsErrorMessage ) {
144
144
return nil , & RateLimitError {Err : tweet .Error }
145
145
}
146
- return nil , & TweeterConnectionError {Err : tweet .Error }
146
+ return nil , & ConnectionError {Err : tweet .Error }
147
147
}
148
148
return nil , TweetNotFoundError
149
149
}
@@ -177,18 +177,19 @@ func MonitorTweets(config types.TradogeConfig) {
177
177
if err != nil {
178
178
log .Println ("Failed to get last tweet:" , err )
179
179
heartbeat .SendFailure ()
180
- }
181
180
182
- if errors .Is (err , & RateLimitError {}) {
183
- log .Println ("Rate limited, waiting 5 minutes..." )
184
- time .Sleep (5 * time .Minute )
185
- continue
186
- } else if errors .Is (err , & TweeterConnectionError {}) {
187
- log .Println ("Failed to connect to Twitter, waiting 5 minutes..." )
188
- time .Sleep (5 * time .Minute )
189
- continue
190
- } else if errors .Is (err , TweetNotFoundError ) {
191
- // No new tweet found so we continue and check again after the delay
181
+ var rateLimitError * RateLimitError
182
+ var connectionError * ConnectionError
183
+
184
+ if errors .As (err , & rateLimitError ) {
185
+ log .Println ("Rate limited, waiting 5 minutes..." )
186
+ time .Sleep (5 * time .Minute )
187
+ } else if errors .As (err , & connectionError ) {
188
+ log .Println ("Failed to connect to Twitter, waiting 5 minutes..." )
189
+ time .Sleep (5 * time .Minute )
190
+ }
191
+ // for TweetNotFoundError No new tweet found so we continue and check again after the delay
192
+ // for other errors we just log and continue
192
193
continue
193
194
}
194
195
0 commit comments