{"record":{"id":"cad032fc548edb4f","repo":"router-for-me/CLIProxyAPI","slug":"create-claude-oauth-s-request-w","errorCode":null,"errorMessage":"create Claude OAuth %s request: %w","messagePattern":"create Claude OAuth (.+?) request: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/claude/anthropic_auth.go","lineNumber":235,"sourceCode":"\treq.Header.Set(\"User-Agent\", \"axios/1.15.2\")\n\treq.Header.Set(\"Accept-Encoding\", \"gzip, compress, deflate, br\")\n\treq.Header.Set(\"Connection\", \"close\")\n\treq.Close = true\n}\n\n// fetchOAuthControlPlaneJSON issues an Axios-shaped OAuth control-plane GET and\n// returns the decoded response body. label names the endpoint in error text.\nfunc (o *ClaudeAuth) fetchOAuthControlPlaneJSON(ctx context.Context, endpoint, accessToken, label string) ([]byte, error) {\n\tif o == nil || o.httpClient == nil {\n\t\treturn nil, fmt.Errorf(\"fetch Claude OAuth %s: HTTP client is nil\", label)\n\t}\n\taccessToken = strings.TrimSpace(accessToken)\n\tif accessToken == \"\" {\n\t\treturn nil, fmt.Errorf(\"fetch Claude OAuth %s: access token is empty\", label)\n\t}\n\treq, errRequest := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)\n\tif errRequest != nil {\n\t\treturn nil, fmt.Errorf(\"create Claude OAuth %s request: %w\", label, errRequest)\n\t}\n\tapplyClaudeOAuthAxiosHeaders(req)\n\treq.Header.Set(\"Authorization\", \"Bearer \"+accessToken)\n\treq.Header.Set(\"Cache-Control\", \"no-cache\")\n\n\tresp, errDo := o.httpClient.Do(req)\n\tif errDo != nil {\n\t\treturn nil, fmt.Errorf(\"fetch Claude OAuth %s: %w\", label, errDo)\n\t}\n\tdefer func() {\n\t\tif errClose := resp.Body.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"failed to close Claude OAuth %s response body: %v\", label, errClose)\n\t\t}\n\t}()\n\tbody, errRead := readClaudeOAuthResponseBody(resp)\n\tif errRead != nil {\n\t\treturn nil, fmt.Errorf(\"read Claude OAuth %s response: %w\", label, errRead)\n\t}","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/claude/anthropic_auth.go#L217-L253","documentation":"Returned by ClaudeAuth.fetchOAuthControlPlaneJSON when http.NewRequestWithContext rejects the GET to the OAuth control-plane endpoint (ProfileURL https://api.anthropic.com/api/oauth/profile or RolesURL). The endpoints are compile-time constants, so parse failure requires them to be edited to a malformed URL or the ctx to be nil. Pure construction-time guard; no network involved.","triggerScenarios":"Overriding ProfileURL/RolesURL constants with a scheme-less or control-character URL in a fork; passing a nil ctx from a custom caller.","commonSituations":"Local development pointing api.anthropic.com at a stub with a typo'd URL; rarely or never seen with stock constants.","solutions":["Fix the malformed endpoint constant (scheme + host must parse)","Pass a non-nil context from the caller","Add a unit test that url.Parse's each endpoint constant"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if ctx == nil { ctx = context.Background() }\nif _, errParse := url.Parse(endpoint); errParse != nil {\n    return fmt.Errorf(\"malformed OAuth endpoint %q\", endpoint)\n}","typeGuard":null,"tryCatchPattern":"if _, err := auth.FetchOAuthProfile(ctx, token); err != nil {\n    var urlErr *url.Error\n    if errors.As(err, &urlErr) { log.Errorf(\"endpoint constant misconfigured: %v\", err) }\n}","preventionTips":["Keep ProfileURL/RolesURL constants untouched or cover them with url.Parse unit tests"],"tags":["claude","http","url","configuration"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}