Skip to content

Commit 4e62bda

Browse files
authored
fix: enrich 403 on org listing with token scope guidance (CLI-89) (#498)
## Problem When `listOrganizations` fails with 403, the error shows: ``` ApiError: Failed to list organizations: 403 Forbidden ``` This happens during auto-detect (event view, issue view) when the token lacks `org:read` scope. Affects **24 users** ([CLI-89](https://sentry.sentry.io/issues/7287298473/)). ## Fix Enhanced the 403 error with token scope guidance: ``` Failed to list organizations: 403 Forbidden Your auth token may lack the required 'org:read' scope. Re-authenticate with: sentry auth login Or check token scopes at: https://sentry.io/settings/auth-tokens/ ```
1 parent a8e4fbb commit 4e62bda

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/lib/api/organizations.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
UserRegionsResponseSchema,
1717
} from "../../types/index.js";
1818

19-
import { withAuthGuard } from "../errors.js";
19+
import { ApiError, withAuthGuard } from "../errors.js";
2020
import {
2121
getApiBaseUrl,
2222
getControlSiloUrl,
@@ -60,8 +60,33 @@ export async function listOrganizationsInRegion(
6060
...config,
6161
});
6262

63-
const data = unwrapResult(result, "Failed to list organizations");
64-
return data as unknown as SentryOrganization[];
63+
try {
64+
const data = unwrapResult(result, "Failed to list organizations");
65+
return data as unknown as SentryOrganization[];
66+
} catch (error) {
67+
// Enrich 403 errors with token scope guidance (CLI-89, 24 users).
68+
// A 403 from the organizations endpoint usually means the auth token
69+
// lacks the org:read scope — either it's an internal integration token
70+
// with limited scopes, or a self-hosted token without the right permissions.
71+
if (error instanceof ApiError && error.status === 403) {
72+
const lines: string[] = [];
73+
if (error.detail) {
74+
lines.push(error.detail, "");
75+
}
76+
lines.push(
77+
"Your auth token may lack the required 'org:read' scope.",
78+
"Re-authenticate with: sentry auth login",
79+
"Or check token scopes at: https://sentry.io/settings/auth-tokens/"
80+
);
81+
throw new ApiError(
82+
error.message,
83+
error.status,
84+
lines.join("\n "),
85+
error.endpoint
86+
);
87+
}
88+
throw error;
89+
}
6590
}
6691

6792
/**

0 commit comments

Comments
 (0)