plandex-ai/plandex · error
Error getting org:
Error message
Error getting org:
What it means
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.
Source
Thrown at app/server/handlers/orgs.go:214
}
w.Write(bytes)
log.Println("Successfully got org session")
}
func ListOrgRolesHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for ListOrgRolesHandler")
auth := Authenticate(w, r, true)
if auth == nil {
return
}
org, err := db.GetOrg(auth.OrgId)
if err != nil {
log.Printf("Error getting org: %v\n", err)
http.Error(w, "Error getting org: "+err.Error(), http.StatusInternalServerError)
return
}
if org.IsTrial {
writeApiError(w, shared.ApiError{
Type: shared.ApiErrorTypeTrialActionNotAllowed,
Status: http.StatusForbidden,
Msg: "Trial user can't list org roles",
})
return
}
if !auth.HasPermission(shared.PermissionListOrgRoles) {
log.Println("User cannot list org roles")
http.Error(w, "User cannot list org roles", http.StatusForbidden)
return
}
View on GitHub (pinned to e2d772072e)
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
Example fix
// before
http.Error(w, "Error getting org: "+err.Error(), http.StatusInternalServerError)
// after
if errors.Is(err, sql.ErrNoRows) {
writeApiError(w, shared.ApiError{Type: shared.ApiErrorTypeOrgNotFound, Status: http.StatusNotFound, Msg: "Org not found"})
return
}
http.Error(w, "Error getting org: "+err.Error(), http.StatusInternalServerError) Defensive patterns
Strategy: try-catch
Validate before calling
// client: ensure token present before calling
if (!apiKey) throw new Error('api key required');
const res = await fetch(base + '/orgs/roles', { headers: { Authorization: 'Bearer ' + apiKey } });
if (res.status === 500) console.error('org lookup failed; check server logs and DB health'); Try / catch
try {
const roles = await listOrgRoles();
} catch (e) {
if (e.status === 500) { /* retry or report server-side DB issue; check server logs */ }
else throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- error getting current plan state params: %v
- error getting contexts: %v
- error loading plan: %v
- error validating project
- error validating plan membership
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/7eb5ee4be736d036.
Report an issue: GitHub.