{"record":{"id":"36f870aaeb101a6e","repo":"AlexxIT/go2rtc","slug":"res-status-36f870","errorCode":null,"errorMessage":"res.Status","messagePattern":"res\\.Status","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/xiaomi/cloud.go","lineNumber":438,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treq.Header.Set(\"Cookie\", c.cookies)\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\n\tfor k, v := range headers {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tres, err := c.client.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer res.Body.Close()\n\n\tif res.StatusCode != http.StatusOK {\n\t\treturn nil, errors.New(res.Status)\n\t}\n\n\tbody, err := io.ReadAll(res.Body)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tciphertext, err := base64.StdEncoding.DecodeString(string(body))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tplaintext, err := crypt(signedNonce, ciphertext)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar res1 struct {","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/xiaomi/cloud.go#L420-L456","documentation":"pkg/xiaomi cloud Request performs an HTTP call to the Xiaomi cloud API. Any non-200 status code is converted to an error whose message is the raw res.Status line (e.g. '403 Forbidden'), since Xiaomi signals failures at the HTTP level rather than in the JSON body.","triggerScenarios":"Calling xiaomi cloud Request when the server returns a non-OK status: expired/invalid auth cookies or service token, rate limiting, server-side 5xx, or wrong endpoint/region.","commonSituations":"Stale stored login cookies after Xiaomi session expiry; calling the wrong regional endpoint (cn vs de vs us); Xiaomi throttling frequent polling requests.","solutions":["Re-login to refresh cookies/service tokens, then retry the request","Check the status code text in the error to identify 401/403 (auth) vs 429 (rate limit) vs 5xx (server)","Verify the correct regional API endpoint for your Xiaomi account","Reduce polling frequency if hitting rate limits"],"exampleFix":"// before\nresp, err := cloud.Request(staleClient, url, payload) // errors: res.Status\n// after\nif err := cloud.Login(user, pass); err != nil { return err } // refresh tokens first\nresp, err := cloud.Request(freshClient, url, payload)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := cloud.Request(client, url, payload)\nif err != nil {\n    if strings.Contains(err.Error(), \"401\") || strings.Contains(err.Error(), \"403\") {\n        // re-authenticate then retry once\n    }\n    return err\n}","preventionTips":["Refresh Xiaomi session cookies proactively before expiry","Use the correct regional endpoint for the account","Back off on 429/5xx instead of hammering the API"],"tags":["xiaomi","cloud","http","api"],"backgroundTag":"http-non-200-response","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}