{"record":{"id":"7eb5ee4be736d036","repo":"plandex-ai/plandex","slug":"error-getting-org-7eb5ee","errorCode":null,"errorMessage":"Error getting org: ","messagePattern":"Error getting org: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/orgs.go","lineNumber":214,"sourceCode":"\t}\n\n\tw.Write(bytes)\n\n\tlog.Println(\"Successfully got org session\")\n}\n\nfunc ListOrgRolesHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for ListOrgRolesHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\torg, err := db.GetOrg(auth.OrgId)\n\tif err != nil {\n\t\tlog.Printf(\"Error getting org: %v\\n\", err)\n\t\thttp.Error(w, \"Error getting org: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tif org.IsTrial {\n\t\twriteApiError(w, shared.ApiError{\n\t\t\tType:   shared.ApiErrorTypeTrialActionNotAllowed,\n\t\t\tStatus: http.StatusForbidden,\n\t\t\tMsg:    \"Trial user can't list org roles\",\n\t\t})\n\t\treturn\n\t}\n\n\tif !auth.HasPermission(shared.PermissionListOrgRoles) {\n\t\tlog.Println(\"User cannot list org roles\")\n\t\thttp.Error(w, \"User cannot list org roles\", http.StatusForbidden)\n\t\treturn\n\t}\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/orgs.go#L196-L232","documentation":"ListOrgRolesHandler fails to fetch the org record from the database (db.GetOrg(auth.OrgId)) and returns HTTP 500 with the wrapped error text. The library throws this when the org lookup errors, which is surfaced only after authentication succeeds and the auth token has been bound to an org ID.","triggerScenarios":"Calling GET for org roles when the org row for auth.OrgId is missing from the orgs table, the database connection is down, or the orgs query fails (e.g. constraint/schema issue or connection pool exhaustion).","commonSituations":"Database not migrated (org row never created), stale auth token referencing a deleted org, Postgres downtime or network interruption between server and DB, connection pool exhausted under load.","solutions":["Check server logs for the full underlying error printed just before the 500 (log.Printf(\"Error getting org: %v\"))","Verify the database is reachable and migrations ran so the org row exists","Confirm the auth token's orgId refers to an existing, non-deleted org","Check connection pool limits / max open connections if errors appear under load"],"exampleFix":"// before\nhttp.Error(w, \"Error getting org: \"+err.Error(), http.StatusInternalServerError)\n// after\nif errors.Is(err, sql.ErrNoRows) {\n    writeApiError(w, shared.ApiError{Type: shared.ApiErrorTypeOrgNotFound, Status: http.StatusNotFound, Msg: \"Org not found\"})\n    return\n}\nhttp.Error(w, \"Error getting org: \"+err.Error(), http.StatusInternalServerError)","handlingStrategy":"try-catch","validationCode":"// client: ensure token present before calling\nif (!apiKey) throw new Error('api key required');\nconst res = await fetch(base + '/orgs/roles', { headers: { Authorization: 'Bearer ' + apiKey } });\nif (res.status === 500) console.error('org lookup failed; check server logs and DB health');","typeGuard":null,"tryCatchPattern":"try {\n  const roles = await listOrgRoles();\n} catch (e) {\n  if (e.status === 500) { /* retry or report server-side DB issue; check server logs */ }\n  else throw e;\n}","preventionTips":["Monitor DB health and connection pool saturation","Ensure migrations run on every deploy","Alert on 500s from org endpoints via server logs","Validate tokens map to live orgs before issuing them"],"tags":["database","http-500","org-lookup"],"backgroundTag":"database-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}