Skip to content

Commit f03f2ec

Browse files
committed
fix: clearer 'select a plan' error when creating a project on an unactivated org
1 parent 73c51ca commit f03f2ec

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

apps/webapp/app/models/project.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { customAlphabet, nanoid } from "nanoid";
33
import slug from "slug";
44
import { $replica, prisma } from "~/db.server";
55
import { projectCreated } from "~/services/projectCreated.server";
6+
import { ServiceValidationError } from "~/v3/services/common.server";
67
import { type Organization, createEnvironment } from "./organization.server";
78
export type { Project } from "@trigger.dev/database";
89

@@ -50,7 +51,10 @@ export async function createProject(
5051

5152
if (version === "v3") {
5253
if (!organization.isActivated) {
53-
throw new Error(`Organization can't create v3 projects.`);
54+
throw new ServiceValidationError(
55+
"You must select a plan for this organization before creating projects.",
56+
402
57+
);
5458
}
5559
}
5660

apps/webapp/app/routes/api.v1.orgs.$orgParam.projects.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
createActionPATApiRoute,
1010
createLoaderPATApiRoute,
1111
} from "~/services/routeBuilders/apiBuilder.server";
12+
import { ServiceValidationError } from "~/v3/services/common.server";
1213
import { isCuid } from "cuid";
1314

1415
const ParamsSchema = z.object({
@@ -108,6 +109,9 @@ export const action = createActionPATApiRoute(
108109

109110
if (error) {
110111
logger.error("Failed to create project", { error });
112+
if (error instanceof ServiceValidationError) {
113+
return json({ error: error.message }, { status: error.status ?? 400 });
114+
}
111115
return json({ error: "Failed to create project" }, { status: 400 });
112116
}
113117

0 commit comments

Comments
 (0)