{"record":{"id":"80320912dd796bf4","repo":"larksuite/cli","slug":"app-registration-failed-read-body-w","errorCode":null,"errorMessage":"app registration failed: read body: %w","messagePattern":"app registration failed: read body: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/app_registration.go","lineNumber":123,"sourceCode":"\tform.Set(\"auth_method\", \"client_secret\")\n\tform.Set(\"request_user_info\", \"open_id tenant_brand\")\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", endpoint, strings.NewReader(form.Encode()))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\n\tresp, err := httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\tlogHTTPResponse(resp)\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"app registration failed: read body: %w\", err)\n\t}\n\n\tvar data map[string]interface{}\n\tif err := json.Unmarshal(body, &data); err != nil {\n\t\treturn nil, fmt.Errorf(\"app registration failed: HTTP %d – response not JSON\", resp.StatusCode)\n\t}\n\n\t_, hasError := data[\"error\"]\n\tif resp.StatusCode >= 400 || hasError {\n\t\tmsg := getStr(data, \"error_description\")\n\t\tif msg == \"\" {\n\t\t\tmsg = getStr(data, \"error\")\n\t\t}\n\t\tif msg == \"\" {\n\t\t\tmsg = \"Unknown error\"\n\t\t}\n\t\treturn nil, fmt.Errorf(\"app registration failed: %s\", msg)\n\t}","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/auth/app_registration.go#L105-L141","documentation":"Thrown by RequestAppRegistration in internal/auth/app_registration.go:123 when io.ReadAll fails while reading the response body of the device-flow 'begin' POST to the account registration endpoint. The library treats an unreadable body as a failed registration because the device_code payload could not be retrieved. The underlying read error is preserved via %w wrapping.","triggerScenarios":"The HTTP response body stream from the app-registration begin endpoint breaks mid-read: connection reset by the server or a proxy, truncated chunked transfer-encoding response, TLS connection dropped mid-response, or the 30s begin-request context deadline elapsing while the body is still streaming.","commonSituations":"Corporate proxies or VPNs killing idle keep-alive connections; flaky mobile/hotel Wi-Fi; server-side load balancers closing connections early; network outages during `lark-cli` first-run app registration.","solutions":["Re-run the registration command; this is usually a transient network failure.","Check connectivity to the Feishu/Lark accounts host (ping/curl the accounts endpoint behind any proxy).","Disable or bypass corporate MITM proxies/VPNs, or configure HTTPS_PROXY correctly.","If it reproduces consistently, inspect whether a firewall or load balancer truncates responses and retry from a different network."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := checkHTTPSEndpointReachable(registrationEndpoint); err != nil { return fmt.Errorf(\"network unreachable before registration: %w\", err) }","typeGuard":null,"tryCatchPattern":"resp, err := RequestAppRegistration(ctx, client, brand, errOut)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) || strings.Contains(err.Error(), \"read body\") {\n        // transient: retry with backoff\n    }\n    return err\n}","preventionTips":["Check network/proxy health before starting device registration.","Avoid flaky networks/VPNs during interactive login flows.","Set explicit HTTPS_PROXY only when the proxy is known-good."],"tags":["network","io","device-flow","http-body"],"backgroundTag":"http-body-read-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}