{"record":{"id":"2613226931a6efa2","repo":"AlexxIT/go2rtc","slug":"err-error-261322","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/ring/ring.go","lineNumber":40,"sourceCode":"\nfunc apiRing(w http.ResponseWriter, r *http.Request) {\n\tquery := r.URL.Query()\n\tvar ringAPI *ring.RingApi\n\n\t// Check auth method\n\tif email := query.Get(\"email\"); email != \"\" {\n\t\t// Email/Password Flow\n\t\tpassword := query.Get(\"password\")\n\t\tcode := query.Get(\"code\")\n\n\t\tvar err error\n\t\tringAPI, err = ring.NewRestClient(ring.EmailAuth{\n\t\t\tEmail:    email,\n\t\t\tPassword: password,\n\t\t}, nil)\n\n\t\tif err != nil {\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\t// Try authentication (this will trigger 2FA if needed)\n\t\tif _, err = ringAPI.GetAuth(code); err != nil {\n\t\t\tif ringAPI.Using2FA {\n\t\t\t\t// Return 2FA prompt\n\t\t\t\tapi.ResponseJSON(w, map[string]interface{}{\n\t\t\t\t\t\"needs_2fa\": true,\n\t\t\t\t\t\"prompt\":    ringAPI.PromptFor2FA,\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t} else if refreshToken := query.Get(\"refresh_token\"); refreshToken != \"\" {\n\t\t// Refresh Token Flow","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/ring/ring.go#L22-L58","documentation":"GET /api/ring with email/password parameters creates a Ring REST client via ring.NewRestClient(ring.EmailAuth{...}, nil). If client construction fails, the handler returns HTTP 500 with the raw error. Construction validates the auth configuration and session setup, so failures mean the Ring client could not even be initialized before authentication was attempted.","triggerScenarios":"Calling /api/ring?email=...&password=... where the underlying Ring session/client initialization errors (bad session state, network failure contacting Ring's auth endpoints, invalid auth configuration struct).","commonSituations":"Ring changing its authentication endpoints requiring a library update; network egress blocked to Ring's cloud API; empty/garbage password values; running an old go2rtc whose Ring library is outdated after Ring API changes.","solutions":["Update go2rtc to the latest release so the bundled Ring library matches current Ring API behavior","Verify outbound HTTPS access to Ring's API endpoints from the go2rtc host","Double-check email/password query values for typos or missing URL-encoding","Prefer the refresh_token flow, which is more stable across Ring auth changes"],"exampleFix":"// before\n/api/ring?email=me@example.com&password=p@ss\n// after (URL-encode special chars)\n/api/ring?email=me@example.com&password=p%40ss\n// or better: use a refresh token\n/api/ring?refresh_token=<token>","handlingStrategy":"validation","validationCode":"if email == \"\" || password == \"\" {\n    return errors.New(\"both email and password query parameters are required\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := http.Get(\"http://server:1984/api/ring?email=...&password=...\")\nif resp.StatusCode == http.StatusInternalServerError {\n    b, _ := io.ReadAll(resp.Body)\n    return fmt.Errorf(\"ring client init failed: %s — update go2rtc or check network egress to Ring\", b)\n}","preventionTips":["Keep go2rtc updated; Ring changes its auth API frequently","URL-encode credentials in query strings","Ensure outbound HTTPS to Ring endpoints from the server","Prefer refresh_token auth once initialized"],"tags":["ring","authentication","cloud"],"backgroundTag":"authentication-required","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"}