{"record":{"id":"6bb0249090a7596c","repo":"goharbor/harbor","slug":"refresh-dockerhub-token-v","errorCode":null,"errorMessage":"refresh dockerhub token: %v","messagePattern":"refresh dockerhub token: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/reg/adapter/dockerhub/client.go","lineNumber":134,"sourceCode":"// ensureToken refreshes the bearer token when it has expired or is close to\n// expiring. It is a no-op for anonymous (unauthenticated) clients.\nfunc (c *Client) ensureToken() error {\n\tif len(c.credential.Identifier) == 0 {\n\t\treturn nil\n\t}\n\tc.mu.Lock()\n\tdefer c.mu.Unlock()\n\tif time.Now().Before(c.tokenExpiry) {\n\t\treturn nil\n\t}\n\treturn c.refreshToken()\n}\n\n// Do performs an HTTP request to DockerHub, refreshing the bearer token when\n// needed and attaching it to the Authorization header.\nfunc (c *Client) Do(method, path string, body io.Reader) (*http.Response, error) {\n\tif err := c.ensureToken(); err != nil {\n\t\treturn nil, fmt.Errorf(\"refresh dockerhub token: %v\", err)\n\t}\n\n\turl := baseURL + path\n\tlog.Infof(\"%s %s\", method, url)\n\treq, err := http.NewRequest(method, url, body)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif body != nil || method == http.MethodPost || method == http.MethodPut {\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t}\n\treq.Header.Set(\"Authorization\", fmt.Sprintf(\"Bearer %s\", c.token))\n\n\treturn c.client.Do(req)\n}\n","sourceCodeStart":116,"sourceCodeEnd":150,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/pkg/reg/adapter/dockerhub/client.go#L116-L150","documentation":"Error \"refresh dockerhub token: %v\" thrown in goharbor/harbor.","triggerScenarios":"Thrown at src/pkg/reg/adapter/dockerhub/client.go:134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}