Add basic HTTP errors handling
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
"golang.org/x/text/transform"
|
||||
@@ -36,9 +37,23 @@ func dumpForumPage(url string) (string, error) {
|
||||
req.AddCookie(c.Cookies[i])
|
||||
}
|
||||
|
||||
resp, err := dclient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
var resp *http.Response
|
||||
retryCount := 0
|
||||
for {
|
||||
if retryCount < 5 {
|
||||
resp, err = dclient.Do(req)
|
||||
if err != nil {
|
||||
if uberDebug {
|
||||
dlog.Debug().Err(err).Int("попытка", retryCount+1).Msg("Не удалось получить данные, пытаемся ещё раз")
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
retryCount++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
Reference in New Issue
Block a user