Repository: strapi/strapi
File: packages/cli/cloud/src/create-project/action.ts (TypeScript)

Code before:
    }
  }
  logger.error(
    'We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance.'
  );
}

async function createProject(
  ctx: CLIContext,
  cloudApi: any,
  projectInput: ProjectInput,
  token: string,
  config: CloudCliConfig
) {
  const { logger } = ctx;
  const spinner = logger.spinner('Setting up your project...').start();
  const notificationService = notificationServiceFactory(ctx);
  const { waitForEnvironmentCreation } = notificationService(
    `${apiConfig.apiBaseUrl}/v1/notifications`,
    token,
    config
  );
  try {
    const { data } = await cloudApi.createProject(projectInput);
    await local.save({ project: data });
    await waitForEnvironmentCreation(data.environmentInternalName);
    spinner.succeed('Project created successfully!');
    return data;
  } catch (e: Error | unknown) {
    spinner.fail('An error occurred while creating the project on Strapi Cloud.');
    throw e;
  }
}

export default async (ctx: CLIContext) => {
  const { logger } = ctx;
  const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);

  const token = await getValidToken(ctx, promptLogin);
  if (!token) {
    return;
  }

  const cloudApi = await cloudApiFactory(ctx, token);
  const { data: config } = await cloudApi.config();
  const projectName = await getProjectNameFromPackageJson(ctx);

  const defaultAnswersMapper = questionDefaultValuesMapper({
    name: projectName,
    nodeVersion: getProjectNodeVersionDefault,
  });

Review comment (bug):
@gonbaum we need to handle the specific error here and let the user know they need to visit the dashboard to retry.

Code after:
        return;
      case 503:
        logger.error(
          'Strapi Cloud project creation is currently unavailable. Please try again later.'
        );
        return;
      default:
        if (errorMessage) {
          logger.error(errorMessage);
          throw error;
        }
        break;
    }
  }
  logger.error(
    'We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance.'
  );
}

async function createProject(
  ctx: CLIContext,
  cloudApi: CloudApiService,
  projectInput: ProjectInput,
  token: string,
  config: CloudCliConfig
) {
  const { logger } = ctx;
  const projectSpinner = logger.spinner('Setting up your project...').start();
  projectSpinner.indent = 1;
  const notificationService = notificationServiceFactory(ctx);
  const { waitForEnvironmentCreation, close } = notificationService(
    `${apiConfig.apiBaseUrl}/${VERSION}/notifications`,
    token,
    config
  );
  let projectData: CreateProjectResponse;
  try {
    const { data } = await cloudApi.createProject(projectInput);
    projectData = data;
    await local.save({ project: data });
    projectSpinner.succeed('Project created successfully!');
  } catch (e: Error | unknown) {
    projectSpinner.fail(`An error occurred while creating the project on Strapi Cloud.`);
    close();
    throw e;
  }
  if (config.featureFlags.asyncProjectCreationEnabled) {
    const environmentSpinner = logger
      .spinner('Setting up your environment... This may take a minute...')
      .start();
    environmentSpinner.indent = 1;