Add basic HTTP errors handling
This commit is contained in:
@@ -6,11 +6,14 @@ package fetcherv1
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func fetch(forumID int) {
|
||||
startPage := "https://" + c.Config.URL + "/forum/viewforum.php?f=" + strconv.Itoa(forumID)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
startPageFile, err := dumpForumPage(startPage)
|
||||
if err != nil {
|
||||
dlog.Error().Err(err).Msg("Не удалось получить данные с форума")
|
||||
|
@@ -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