Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/lib/init/preflight.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SentryTeam } from "../../types/index.js";
import { listOrganizations } from "../api-client.js";
import { getAuthToken } from "../db/auth.js";
import { WizardError } from "../errors.js";
import { ApiError, WizardError } from "../errors.js";
import { resolveOrCreateTeam } from "../resolve-team.js";
import { slugify } from "../utils.js";
import { WizardCancelledError } from "./clack-utils.js";
Expand Down Expand Up @@ -352,7 +352,23 @@ async function resolveOrgSlug(
return resolved.org;
}

const orgs = await listOrganizations();
let orgs: Awaited<ReturnType<typeof listOrganizations>>;
try {
orgs = await listOrganizations();
} catch (error) {
if (error instanceof ApiError && error.status === 403) {
const lines: string[] = ["Could not list organizations (403 Forbidden)."];
if (error.detail) {
lines.push(error.detail, "");
}
lines.push(
"Specify the org on the command line: sentry init <org-slug>/",
"Or set an environment variable: SENTRY_ORG=<org-slug> sentry init"
);
return { ok: false, error: lines.join("\n ") };
}
throw error;
}
if (orgs.length === 0) {
return {
ok: false,
Expand Down
Loading