{"record":{"id":"fda83feeacae93eb","repo":"router-for-me/CLIProxyAPI","slug":"xai-discovery-parse-response-w","errorCode":null,"errorMessage":"xai discovery: parse response: %w","messagePattern":"xai discovery: parse response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/xai/xai.go","lineNumber":97,"sourceCode":"\t}\n\tdefer func() {\n\t\tif errClose := resp.Body.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"xai discovery: close response body error: %v\", errClose)\n\t\t}\n\t}()\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"xai discovery: read response: %w\", err)\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"xai discovery failed with status %d: %s\", resp.StatusCode, strings.TrimSpace(string(body)))\n\t}\n\tvar payload struct {\n\t\tDeviceAuthorizationEndpoint string `json:\"device_authorization_endpoint\"`\n\t\tTokenEndpoint               string `json:\"token_endpoint\"`\n\t}\n\tif err = json.Unmarshal(body, &payload); err != nil {\n\t\treturn nil, fmt.Errorf(\"xai discovery: parse response: %w\", err)\n\t}\n\tdeviceAuthorizationEndpoint, err := ValidateOAuthEndpoint(payload.DeviceAuthorizationEndpoint, \"device_authorization_endpoint\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ttokenEndpoint, err := ValidateOAuthEndpoint(payload.TokenEndpoint, \"token_endpoint\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn &Discovery{\n\t\tDeviceAuthorizationEndpoint: deviceAuthorizationEndpoint,\n\t\tTokenEndpoint:               tokenEndpoint,\n\t}, nil\n}\n\n// StartDeviceFlow requests a device code from xAI.\nfunc (a *XAIAuth) StartDeviceFlow(ctx context.Context) (*DeviceCodeResponse, error) {\n\tdiscovery, errDiscover := a.Discover(ctx)","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/xai/xai.go#L79-L115","documentation":"Error \"xai discovery: parse response: %w\" thrown in router-for-me/CLIProxyAPI.","triggerScenarios":"Thrown at internal/auth/xai/xai.go:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the discovery endpoint returned valid JSON; inspect the wrapped parse error.","Check for proxy error pages returned instead of the discovery document."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}