Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 14 additions & 2 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { DEFAULT_PRISMIC_HOST } from "../env";
import { openBrowser } from "../lib/browser";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { installDependencies } from "../lib/packageJson";
import { ForbiddenRequestError, UnauthorizedRequestError } from "../lib/request";
import {
ForbiddenRequestError,
NotFoundRequestError,
UnauthorizedRequestError,
} from "../lib/request";
import { checkIsTypeBuilderEnabled, TypeBuilderRequiredError } from "../project";
import { syncCustomTypes, syncSlices } from "./sync";

Expand Down Expand Up @@ -104,7 +108,15 @@ export default createCommand(config, async ({ values }) => {
);
}

const isTypeBuilderEnabled = await checkIsTypeBuilderEnabled(repo, { token, host });
let isTypeBuilderEnabled;
try {
isTypeBuilderEnabled = await checkIsTypeBuilderEnabled(repo, { token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
throw error;
}
if (!isTypeBuilderEnabled) {
throw new TypeBuilderRequiredError();
}
Expand Down
5 changes: 4 additions & 1 deletion src/commands/locale-add.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { upsertLocale } from "../clients/locale";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand Down Expand Up @@ -32,6 +32,9 @@ export default createCommand(config, async ({ positionals, values }) => {
try {
await upsertLocale({ id: code, isMaster: master, customName: name }, { repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to add locale: ${message}`);
Expand Down
17 changes: 15 additions & 2 deletions src/commands/locale-list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getHost, getToken } from "../auth";
import { getLocales } from "../clients/locale";
import { createCommand, type CommandConfig } from "../lib/command";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { stringify } from "../lib/json";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand All @@ -24,7 +25,19 @@ export default createCommand(config, async ({ values }) => {
const token = await getToken();
const host = await getHost();

const locales = await getLocales({ repo, token, host });
let locales;
try {
locales = await getLocales({ repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to list locales: ${message}`);
}
throw error;
}

if (json) {
console.info(stringify(locales));
Expand Down
5 changes: 4 additions & 1 deletion src/commands/locale-remove.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { removeLocale } from "../clients/locale";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand Down Expand Up @@ -30,6 +30,9 @@ export default createCommand(config, async ({ positionals, values }) => {
try {
await removeLocale(code, { repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to remove locale: ${message}`);
Expand Down
27 changes: 15 additions & 12 deletions src/commands/locale-set-master.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { getLocales, upsertLocale } from "../clients/locale";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand All @@ -27,25 +27,28 @@ export default createCommand(config, async ({ positionals, values }) => {
const token = await getToken();
const host = await getHost();

const locales = await getLocales({ repo, token, host });
const locale = locales.find((l) => l.id === code);
try {
const locales = await getLocales({ repo, token, host });
const locale = locales.find((l) => l.id === code);

if (!locale) {
throw new CommandError(
`Locale "${code}" not found. Available locales: ${locales.map((l) => l.id).join(", ")}`,
);
}
if (!locale) {
throw new CommandError(
`Locale "${code}" not found. Available locales: ${locales.map((l) => l.id).join(", ")}`,
);
}

if (locale.isMaster) {
throw new CommandError(`Locale "${code}" is already the master.`);
}
if (locale.isMaster) {
throw new CommandError(`Locale "${code}" is already the master.`);
}

try {
await upsertLocale(
{ id: locale.id, isMaster: true, customName: locale.customName ?? undefined },
{ repo, token, host },
);
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to set master locale: ${message}`);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/preview-add.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { addPreview } from "../clients/core";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand Down Expand Up @@ -42,6 +42,9 @@ export default createCommand(config, async ({ positionals, values }) => {
try {
await addPreview({ name: displayName, websiteURL, resolverPath }, { repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to add preview: ${message}`);
Expand Down
24 changes: 19 additions & 5 deletions src/commands/preview-list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getHost, getToken } from "../auth";
import { getPreviews, getSimulatorUrl } from "../clients/core";
import { createCommand, type CommandConfig } from "../lib/command";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { stringify } from "../lib/json";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand All @@ -24,10 +25,23 @@ export default createCommand(config, async ({ values }) => {
const token = await getToken();
const host = await getHost();

const [previews, simulatorUrl] = await Promise.all([
getPreviews({ repo, token, host }),
getSimulatorUrl({ repo, token, host }),
]);
let previews;
let simulatorUrl;
try {
[previews, simulatorUrl] = await Promise.all([
getPreviews({ repo, token, host }),
getSimulatorUrl({ repo, token, host }),
]);
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to list previews: ${message}`);
}
throw error;
}

if (json) {
console.info(
Expand Down
17 changes: 10 additions & 7 deletions src/commands/preview-remove.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { getPreviews, removePreview } from "../clients/core";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand All @@ -27,15 +27,18 @@ export default createCommand(config, async ({ positionals, values }) => {
const token = await getToken();
const host = await getHost();

const previews = await getPreviews({ repo, token, host });
const preview = previews.find((p) => p.url === previewUrl);
if (!preview) {
throw new CommandError(`Preview not found: ${previewUrl}`);
}

try {
const previews = await getPreviews({ repo, token, host });
const preview = previews.find((p) => p.url === previewUrl);
if (!preview) {
throw new CommandError(`Preview not found: ${previewUrl}`);
}

await removePreview(preview.id, { repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to remove preview: ${message}`);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/preview-set-simulator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { setSimulatorUrl } from "../clients/core";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand Down Expand Up @@ -45,6 +45,9 @@ export default createCommand(config, async ({ positionals, values }) => {
try {
await setSimulatorUrl(simulatorUrl, { repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to set simulator URL: ${message}`);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/repo-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getAdapter } from "../adapters";
import { getHost, getToken } from "../auth";
import { checkIsDomainAvailable, createRepository } from "../clients/wroom";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";

const MAX_DOMAIN_TRIES = 5;

Expand Down Expand Up @@ -31,6 +31,9 @@ export default createCommand(config, async ({ values }) => {
try {
await createRepository({ domain, name: name ?? domain, framework, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${domain}`);
}
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to create repository: ${message}`);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/repo-set-api-access.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { type RepositoryAccessLevel, setRepositoryAccess } from "../clients/wroom";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const VALID_LEVELS: RepositoryAccessLevel[] = ["private", "public", "open"];
Expand Down Expand Up @@ -38,6 +38,9 @@ export default createCommand(config, async ({ positionals, values }) => {
try {
await setRepositoryAccess(level as RepositoryAccessLevel, { repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to set repository access: ${message}`);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/repo-set-name.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost, getToken } from "../auth";
import { setRepositoryName } from "../clients/wroom";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand Down Expand Up @@ -31,6 +31,9 @@ export default createCommand(config, async ({ positionals, values }) => {
try {
confirmedName = await setRepositoryName(displayName, { repo, token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to set repository name: ${message}`);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/repo-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getProfile } from "../clients/user";
import { getRepositoryAccess } from "../clients/wroom";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { stringify } from "../lib/json";
import { UnknownRequestError } from "../lib/request";
import { NotFoundRequestError, UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";

const config = {
Expand Down Expand Up @@ -43,6 +43,9 @@ export default createCommand(config, async ({ values }) => {
getRepositoryAccess({ repo, token, host }),
]);
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
if (error instanceof UnknownRequestError) {
const message = await error.text();
throw new CommandError(`Failed to fetch repository details: ${message}`);
Expand Down
13 changes: 11 additions & 2 deletions src/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { getAdapter, type Adapter } from "../adapters";
import { getHost, getToken } from "../auth";
import { getCustomTypes, getSlices } from "../clients/custom-types";
import { env } from "../env";
import { createCommand, type CommandConfig } from "../lib/command";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { NotFoundRequestError } from "../lib/request";
import { segmentTrackEnd, segmentTrackStart } from "../lib/segment";
import { dedent } from "../lib/string";
import { checkIsTypeBuilderEnabled, getRepositoryName, TypeBuilderRequiredError } from "../project";
Expand Down Expand Up @@ -34,7 +35,15 @@ export default createCommand(config, async ({ values }) => {

const token = await getToken();
const host = await getHost();
const isTypeBuilderEnabled = await checkIsTypeBuilderEnabled(repo, { token, host });
let isTypeBuilderEnabled;
try {
isTypeBuilderEnabled = await checkIsTypeBuilderEnabled(repo, { token, host });
} catch (error) {
if (error instanceof NotFoundRequestError) {
throw new CommandError(`Repository not found: ${repo}`);
}
throw error;
}
if (!isTypeBuilderEnabled) {
throw new TypeBuilderRequiredError();
}
Expand Down
Loading