1

Add basic HTTP errors handling

This commit is contained in:
2019-09-28 20:20:23 +04:00
parent a504299150
commit a599d898b0
3 changed files with 37 additions and 6 deletions

View File

@@ -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()