{"record":{"id":"8f06a9ca5ac6e7df","repo":"AlexxIT/go2rtc","slug":"d-s","errorCode":null,"errorMessage":"%d: %s","messagePattern":"%d: %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/roborock/api.go","lineNumber":54,"sourceCode":"\t\treturn \"\", err\n\t}\n\n\tclient := http.Client{Timeout: time.Second * 5000}\n\tres, err := client.Do(req)\n\n\tvar v struct {\n\t\tMsg  string `json:\"msg\"`\n\t\tCode int    `json:\"code\"`\n\t\tData struct {\n\t\t\tURL string `json:\"url\"`\n\t\t} `json:\"data\"`\n\t}\n\tif err = json.NewDecoder(res.Body).Decode(&v); err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif v.Code != 200 {\n\t\treturn \"\", fmt.Errorf(\"%d: %s\", v.Code, v.Msg)\n\t}\n\n\treturn v.Data.URL, nil\n}\n\nfunc Login(baseURL, username, password string) (*UserInfo, error) {\n\tu := baseURL + \"/api/v1/login?username=\" + url.QueryEscape(username) +\n\t\t\"&password=\" + url.QueryEscape(password) + \"&needtwostepauth=false\"\n\treq, err := http.NewRequest(\"POST\", u, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tclientID := core.RandString(16, 64)\n\tclientID = base64.StdEncoding.EncodeToString([]byte(clientID))\n\treq.Header.Set(\"header_clientid\", clientID)\n\n\tclient := http.Client{Timeout: time.Second * 5000}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/roborock/api.go#L36-L72","documentation":"GetBaseURL calls the Roborock API and decodes a JSON envelope containing Code and Msg fields. When the server responds with a code other than 200, the function returns an error formatted as \"<code>: <msg>\". This is the library's way of surfacing Roborock API-level errors (auth failures, bad requests, rate limits) carried inside an otherwise successful HTTP response.","triggerScenarios":"Calling GetBaseURL when the Roborock server rejects the request: invalid credentials, expired token, wrong endpoint region, or server-side error — any response whose JSON body has Code != 200.","commonSituations":"Wrong regional base URL for your account; expired login session; Roborock service outage or rate limiting; passing malformed credentials.","solutions":["Read the numeric code and Msg in the error to identify the API failure (e.g. auth vs server error).","Verify username/password or refresh the auth token, then retry.","Use the correct regional base URL for your Roborock account (EU/US/CN etc.).","Retry after a delay if the code indicates rate limiting or a transient server error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if baseURL == \"\" || username == \"\" || password == \"\" {\n    return errors.New(\"baseURL, username and password are required\")\n}","typeGuard":null,"tryCatchPattern":"url, err := roborock.GetBaseURL(client)\nif err != nil {\n    var apiErr *roborock.APIError // or parse \"<code>: <msg>\"\n    // log code and message, decide whether to retry (5xx/throttle) or fail (auth)\n    return err\n}","preventionTips":["Use the correct regional base URL for the account.","Keep credentials/tokens fresh; re-login on auth-coded failures.","Retry with backoff on transient server codes."],"tags":["roborock","api","http"],"backgroundTag":"api-error-response","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}