chenhg5/cc-connect · error · errUnauthorized

%s: %w

Error message

%s: %w

What it means

webex httpClient.doWithRetry wraps the transport error from do() for every Webex REST call (GetMe, CreateDevice, DeleteDevice, GetMessage, DownloadFile, PostMessage); the 'what' label names the operation. 401 (errUnauthorized) and 429 (Retry-After) handling happen only after this wrapper returns a response.

Source

Thrown at platform/webex/client.go:82

	}
	req.Header.Set("Authorization", "Bearer "+c.token)
	if contentType != "" {
		req.Header.Set("Content-Type", contentType)
	}
	return c.hc.Do(req)
}

// doWithRetry wraps do to surface 401 as errUnauthorized and to retry once on
// 429 after honoring the Retry-After header (capped). The returned response (on
// success) has an unread body the caller must close.
func (c *httpClient) doWithRetry(ctx context.Context, method, url string, body []byte, contentType, what string) (*http.Response, error) {
	resp, err := c.do(ctx, method, url, body, contentType)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode == http.StatusUnauthorized {
		_ = resp.Body.Close()
		return nil, fmt.Errorf("%s: %w", what, errUnauthorized)
	}
	if resp.StatusCode == http.StatusTooManyRequests {
		wait := retryAfter(resp.Header.Get("Retry-After"))
		_ = resp.Body.Close()
		select {
		case <-ctx.Done():
			return nil, ctx.Err()
		case <-time.After(wait):
		}
		resp, err = c.do(ctx, method, url, body, contentType)
		if err != nil {
			return nil, err
		}
		if resp.StatusCode == http.StatusUnauthorized {
			_ = resp.Body.Close()
			return nil, fmt.Errorf("%s: %w", what, errUnauthorized)
		}
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check network/proxy reachability of Webex APIs and retry transient errors
  2. A 401 is surfaced as errUnauthorized for token refresh upstream
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at platform/webex/client.go:82 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/04e7da4950ab7e1e. Report an issue: GitHub.