Catch bw limit errors and prevent repair loops

This commit is contained in:
Ben Adrian Sarmiento
2024-06-24 00:38:57 +02:00
parent a0c13af94b
commit 449c0f71cf
5 changed files with 139 additions and 83 deletions

View File

@@ -293,19 +293,22 @@ func backoffFunc(attempt int) time.Duration {
return time.Duration(backoff) * time.Second
}
func (r *HTTPClient) VerifyURL(url string) bool {
func (r *HTTPClient) VerifyURL(url string) error {
req, err := http.NewRequest(http.MethodHead, url, nil)
if err != nil {
return false
return err
}
timeout := time.Duration(r.timeoutSecs) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
req = req.WithContext(ctx)
resp, _ := r.Do(req)
if resp != nil {
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
resp, err := r.Do(req)
if err != nil {
return err
}
return false
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
return nil
}