diff --git a/handler.go b/handler.go index 787bfe0..ed702f3 100644 --- a/handler.go +++ b/handler.go @@ -323,6 +323,14 @@ func (ca *Cagent) RunHeartbeat(interrupt chan struct{}) { // for error code 429, wait 10 seconds and try again retryIn = 10 * time.Second log.Infof("RunHeartbeat: HTTP 429, too many requests, retrying in %v", retryIn) + } else if err == ErrHubUnauthorized { + // increase sleep time by 30 seconds until it is 1 hour + if ca.Config.Sleep < 60*60 { + ca.Config.Sleep += 30 + } + retries = 0 + retryIn = time.Duration(ca.Config.Sleep) * time.Second + log.Infof("Run: failed to send heartbeat to hub. unable to authorize with provided Hub credentials (HTTP 401). waiting %v seconds until next attempt", ca.Config.Sleep) } else if err == ErrHubServerError { // for error codes 5xx, wait for configured amount of time and try again retryIn = time.Duration(ca.Config.OnHTTP5xxRetryInterval) * time.Second @@ -379,6 +387,9 @@ func (ca *Cagent) sendHeartbeat() error { if resp.StatusCode == http.StatusTooManyRequests { return ErrHubTooManyRequests } + if resp.StatusCode == http.StatusUnauthorized { + return ErrHubUnauthorized + } if resp.StatusCode >= 500 && resp.StatusCode <= 599 { return ErrHubServerError }