Skip to content

Commit

Permalink
fix: workaround hetzner api sometimes return 404
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario-F committed Dec 27, 2021
1 parent 8a7fe9a commit 48bd282
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/hetzner/hetzner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"sync"
"time"

"github.com/Mario-F/hetzner-dyndns/internal/logger"
)
Expand Down Expand Up @@ -91,9 +92,20 @@ func getRequest(uri string) responses {
panic(parseFormErr)
}

resp, err := client.Do(req)
if err != nil {
panic(err)
var resp *http.Response
finshed := false
for i := 0; i < 3 && !finshed; i++ {
resp, err = client.Do(req)
if err != nil {
panic(err)
}

if resp.StatusCode == 404 {
logger.Infof("Hetzner API returned 404, retry.")
time.Sleep(2 * time.Second)
continue
}
finshed = true
}
if resp.StatusCode != 200 {
panic(errors.New(resp.Status))
Expand Down

0 comments on commit 48bd282

Please sign in to comment.