fix(agent): add retry with backoff and WebSocket connect for daemon registration

This commit is contained in:
Deivid Soto 2026-04-06 17:26:32 +02:00
parent 8388220dae
commit 6f81a2f3ea
4 changed files with 73 additions and 6 deletions

View file

@ -246,14 +246,14 @@ func (c *Client) handleResponse(resp *http.Response, dst any) error {
// Try to parse as JSON error
var errResp ErrorResponse
if json.Unmarshal(body, &errResp) == nil && errResp.Error != "" {
return fmt.Errorf("API error %d: %s", resp.StatusCode, errResp.Error)
return &HTTPError{StatusCode: resp.StatusCode, Message: errResp.Error}
}
// Non-JSON response (e.g. HTML error page) — truncate to something readable
msg := string(body)
if len(msg) > 120 || strings.Contains(msg, "<html") || strings.Contains(msg, "<!DOCTYPE") {
msg = fmt.Sprintf("server returned %s (non-JSON response, likely a server error)", resp.Status)
}
return fmt.Errorf("API error %d: %s", resp.StatusCode, msg)
return &HTTPError{StatusCode: resp.StatusCode, Message: msg}
}
if dst != nil {