{"record":{"id":"5541e1bcedd2b7ab","repo":"sipeed/picoclaw","slug":"unexpected-status-s","errorCode":null,"errorMessage":"unexpected status %s","messagePattern":"unexpected status (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/picoclaw/internal/auth/wecom.go","lineNumber":405,"sourceCode":"\treturn u.String(), nil\n}\n\nfunc doWeComJSONGet(ctx context.Context, client *http.Client, targetURL string, out any) error {\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, targetURL, nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, readErr := io.ReadAll(io.LimitReader(resp.Body, 8192))\n\t\tif readErr != nil {\n\t\t\treturn fmt.Errorf(\"unexpected status %s\", resp.Status)\n\t\t}\n\t\treturn fmt.Errorf(\"unexpected status %s: %s\", resp.Status, strings.TrimSpace(string(body)))\n\t}\n\n\tif err := json.NewDecoder(resp.Body).Decode(out); err != nil {\n\t\treturn fmt.Errorf(\"decode JSON response: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc wecomPlatformCode() int {\n\tswitch runtime.GOOS {\n\tcase \"darwin\":\n\t\treturn 1\n\tcase \"windows\":\n\t\treturn 2\n\tcase \"linux\":","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/cmd/picoclaw/internal/auth/wecom.go#L387-L423","documentation":"The WeCom HTTP GET returned a non-200 status AND reading (up to 8KB of) the response body also failed. The double failure means the connection broke mid-response (e.g. reset after headers), so the error carries only the status line like 'unexpected status 502 Bad Gateway' without the body detail that error 137 includes.","triggerScenarios":"Server sends a 5xx status then resets the connection before the body; proxy tears down the stream; mobile/flaky network dropping between headers and body; very large headers plus tiny timeouts.","commonSituations":"Flaky mobile hotspot during login; aggressive firewall RST; relay crash mid-response.","solutions":["Retry the login — a reset mid-body is usually transient","If persistent, curl -v the endpoint to see whether the status+reset reproduces","Check for middleboxes/proxies that reset long-lived or suspicious responses","Update picoclaw if the relay changed behavior (new default endpoints)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"func isConnectionReset(err error) bool {\n\treturn errors.Is(err, syscall.ECONNRESET) || strings.Contains(err.Error(), \"connection reset\")\n}","tryCatchPattern":"if resp.StatusCode != http.StatusOK {\n\tbody, readErr := io.ReadAll(io.LimitReader(resp.Body, 8192))\n\tif readErr != nil {\n\t\t// transient reset: retry the request once before failing\n\t}\n\treturn fmt.Errorf(\"unexpected status %s: %s\", resp.Status, strings.TrimSpace(string(body)))\n}","preventionTips":["Retry once on mid-body resets; they rarely persist","Flag flaky networks/middleboxes when resets recur"],"tags":["go","wecom","http","network"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}