goharbor/harbor · error

refresh dockerhub token: %v

Error message

refresh dockerhub token: %v

What it means

Error "refresh dockerhub token: %v" thrown in goharbor/harbor.

Source

Thrown at src/pkg/reg/adapter/dockerhub/client.go:134

// ensureToken refreshes the bearer token when it has expired or is close to
// expiring. It is a no-op for anonymous (unauthenticated) clients.
func (c *Client) ensureToken() error {
	if len(c.credential.Identifier) == 0 {
		return nil
	}
	c.mu.Lock()
	defer c.mu.Unlock()
	if time.Now().Before(c.tokenExpiry) {
		return nil
	}
	return c.refreshToken()
}

// Do performs an HTTP request to DockerHub, refreshing the bearer token when
// needed and attaching it to the Authorization header.
func (c *Client) Do(method, path string, body io.Reader) (*http.Response, error) {
	if err := c.ensureToken(); err != nil {
		return nil, fmt.Errorf("refresh dockerhub token: %v", err)
	}

	url := baseURL + path
	log.Infof("%s %s", method, url)
	req, err := http.NewRequest(method, url, body)
	if err != nil {
		return nil, err
	}
	if body != nil || method == http.MethodPost || method == http.MethodPut {
		req.Header.Set("Content-Type", "application/json")
	}
	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.token))

	return c.client.Do(req)
}

View on GitHub (pinned to 7b2fd08cc5)

When it happens

Trigger: Thrown at src/pkg/reg/adapter/dockerhub/client.go:134 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/6bb0249090a7596c. Report an issue: GitHub.