{"record":{"id":"6322bba5341d5058","repo":"plandex-ai/plandex","slug":"error-getting-invite-for-org-user","errorCode":null,"errorMessage":"error getting invite for org user","messagePattern":"error getting invite for org user","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/auth_helpers.go","lineNumber":541,"sourceCode":"\t// validate the org membership\n\tisMember, err := db.ValidateOrgMembership(authToken.UserId, parsed.OrgId)\n\n\tif err != nil {\n\t\tlog.Printf(\"error validating org membership: %v\\n\", err)\n\t\tif raiseErr {\n\t\t\thttp.Error(w, \"error validating org membership\", http.StatusInternalServerError)\n\t\t}\n\t\treturn nil\n\t}\n\n\tif !isMember {\n\t\t// check if there's an invite for this user and accept it if so (adds the user to the org)\n\t\tinvite, err := db.GetActiveInviteByEmail(parsed.OrgId, user.Email)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"error getting invite for org user: %v\\n\", err)\n\t\t\tif raiseErr {\n\t\t\t\thttp.Error(w, \"error getting invite for org user\", http.StatusInternalServerError)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\n\t\tif invite != nil {\n\t\t\tlog.Println(\"accepting invite\")\n\n\t\t\terr := db.AcceptInvite(r.Context(), invite, authToken.UserId)\n\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"error accepting invite: %v\\n\", err)\n\t\t\t\tif raiseErr {\n\t\t\t\t\thttp.Error(w, \"error accepting invite\", http.StatusInternalServerError)\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t} else {","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/auth_helpers.go#L523-L559","documentation":"After determining the user is not a member, the server checks for a pending invite via db.GetActiveInviteByEmail(parsed.OrgId, user.Email); an error there logs 'error getting invite for org user' and returns HTTP 500 when raiseErr is true. A backend failure in the invite lookup, not an auth failure of the user.","triggerScenarios":"Non-member user with an OrgId hits an org-scoped endpoint and the invites-table query fails (DB down, timeout, bad schema/query).","commonSituations":"Database outages; invites table missing/migrated; email-case mismatches causing query logic issues; connection-pool exhaustion under load.","solutions":["Check database health and inspect logs for the underlying GetActiveInviteByEmail error","Retry the request once the DB is healthy","Verify the invites schema matches the current application version","Confirm the user's email stored in DB is correct/normalized for invite lookup"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := doCall(ctx); err != nil {\n\tvar apiErr *APIError\n\tif errors.As(err, &apiErr) && apiErr.StatusCode == 500 && strings.Contains(apiErr.Message, \"invite for org user\") {\n\t\treturn retryAfterDBRecovery(ctx) // transient DB failure on invite lookup\n\t}\n\treturn err\n}","preventionTips":["Monitor DB health and the invites table schema in migrations","Normalize user emails (lowercase/trim) so invite lookups match","Add indexes on (org_id, email) for invite lookups","Retry transient failures with exponential backoff"],"tags":["database","invites","internal-server-error"],"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-14T00:17:10.932Z"}