{"record":{"id":"3093034446c3e372","repo":"router-for-me/CLIProxyAPI","slug":"decode-claude-oauth-s-response-w","errorCode":null,"errorMessage":"decode Claude OAuth %s response: %w","messagePattern":"decode Claude OAuth (.+?) response: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/claude/oauth_response.go","lineNumber":66,"sourceCode":"\t\treader = gzipReader\n\tcase \"deflate\":\n\t\tzlibReader, errZlib := zlib.NewReader(bytes.NewReader(encoded))\n\t\tif errZlib == nil {\n\t\t\treader = zlibReader\n\t\t} else {\n\t\t\treader = flate.NewReader(bytes.NewReader(encoded))\n\t\t}\n\tcase \"br\":\n\t\treader = io.NopCloser(brotli.NewReader(bytes.NewReader(encoded)))\n\tcase \"compress\":\n\t\treader = lzw.NewReader(bytes.NewReader(encoded), lzw.MSB, 8)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"decode Claude OAuth response: unsupported content encoding %q\", encoding)\n\t}\n\tdecoded, errDecoded := io.ReadAll(reader)\n\tif errDecoded != nil {\n\t\t_ = reader.Close()\n\t\treturn nil, fmt.Errorf(\"decode Claude OAuth %s response: %w\", encoding, errDecoded)\n\t}\n\tif errClose := reader.Close(); errClose != nil {\n\t\treturn nil, fmt.Errorf(\"close Claude OAuth %s decoder: %w\", encoding, errClose)\n\t}\n\treturn decoded, nil\n}\n","sourceCodeStart":48,"sourceCodeEnd":73,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/claude/oauth_response.go#L48-L73","documentation":"The encoding was recognized and its reader constructed, but reading the decoded stream failed before EOF. The wrapping message includes which encoding was in play, and the underlying error is usually 'unexpected EOF', a corrupt stream, or a connection reset. It means the body started out decodable but broke partway through.","triggerScenarios":"Truncated OAuth response bodies (connection closed mid-body), corrupted deflate/zlib streams where the raw-flate fallback also fails, brotli streams interrupted mid-read, or a proxy re-chunking the body incorrectly.","commonSituations":"Mobile/unstable networks during token refresh; aggressive proxy buffering that cuts large responses; servers under load closing keep-alive connections early; snapshot-replay test data truncated at a fixed buffer size.","solutions":["Retry the request with backoff — mid-stream truncation is usually transient.","Send Accept-Encoding: identity to remove the decoding step entirely.","Increase client read timeouts or disable keep-alive reuse for the OAuth endpoint if resets recur.","Check the underlying error text (unexpected EOF vs corrupt input) to distinguish network truncation from proxy corruption."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"body, err := decode(body, enc)\nif err != nil && (errors.Is(err, io.ErrUnexpectedEOF) || strings.Contains(err.Error(), \"connection reset\")) {\n    // truncated mid-stream: safe to retry the whole request once\n    resp, _ = client.Do(req)\n    body, err = decode(resp.Body, enc)\n}","preventionTips":["Treat unexpected-EOF decode failures as retryable, corrupt-input failures as fatal.","Use identity encoding on flaky links to shrink the decoding failure surface."],"tags":["claude","oauth","network","encoding","retry"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}