Skip to content

Commit

Permalink
Remove unreachable sandbox error code
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Jan 10, 2025
1 parent 1281aa7 commit 3cbb2c0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 114 deletions.
1 change: 1 addition & 0 deletions commands/sandbox/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ exports.handler = async options => {

// Check usage limits and exit if parent portal has no available sandboxes for the selected type
try {
console.log('validate usage limit');
await validateSandboxUsageLimits(accountConfig, sandboxType, env);
} catch (err) {
if (isMissingScopeError(err)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/buildAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async function buildNewAccount({
});

if (isSandbox) {
handleSandboxCreateError(err, env, accountConfig, name, accountId);
handleSandboxCreateError(err, env, name, accountId);
}
if (isDeveloperTestAccount) {
handleDeveloperTestAccountCreateError(err, env, accountId, portalLimit);
Expand Down
114 changes: 1 addition & 113 deletions lib/sandboxes.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { logger } from '@hubspot/local-dev-lib/logger';
import { getSandboxUsageLimits } from '@hubspot/local-dev-lib/api/sandboxHubs';
import { fetchTypes } from '@hubspot/local-dev-lib/api/sandboxSync';
import {
getAccountId,
getEnv,
getConfigAccounts,
} from '@hubspot/local-dev-lib/config';
import { getAccountId, getConfigAccounts } from '@hubspot/local-dev-lib/config';
import { getHubSpotWebsiteOrigin } from '@hubspot/local-dev-lib/urls';
import { HUBSPOT_ACCOUNT_TYPES } from '@hubspot/local-dev-lib/constants/config';
import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
import {
isMissingScopeError,
isSpecifiedError,
} from '@hubspot/local-dev-lib/errors/index';
import { getValidEnv } from '@hubspot/local-dev-lib/environment';
import { AccountType, CLIAccount } from '@hubspot/local-dev-lib/types/Accounts';
import { Environment } from '@hubspot/local-dev-lib/types/Config';

Expand Down Expand Up @@ -69,23 +64,6 @@ function getHasSandboxesByType(
return false;
}

class SandboxLimitError {
context?: {
limit?: string[];
};
}

function getSandboxLimit(error: unknown): number {
// Error context should contain a limit property with a list of one number. That number is the current limit

if (error instanceof SandboxLimitError) {
const limit =
error.context && error.context.limit && error.context.limit[0];
return limit ? parseInt(limit, 10) : 1; // Default to 1
}
return 1;
}

// Fetches available sync types for a given sandbox portal
export async function getAvailableSyncTypes(
parentAccountConfig: CLIAccount,
Expand Down Expand Up @@ -206,7 +184,6 @@ export async function validateSandboxUsageLimits(
export function handleSandboxCreateError(
err: unknown,
env: Environment,
accountConfig: CLIAccount,
name: string,
accountId: number
) {
Expand Down Expand Up @@ -255,95 +232,6 @@ export function handleSandboxCreateError(
})
);
logger.log('');
} else if (
isSpecifiedError(err, {
statusCode: 400,
category: 'VALIDATION_ERROR',
subCategory:
'SandboxErrors.NUM_DEVELOPMENT_SANDBOXES_LIMIT_EXCEEDED_ERROR',
}) &&
'error' in err &&
err.error instanceof Error
) {
logger.log('');
const devSandboxLimit = getSandboxLimit(err.error);
const plural = devSandboxLimit !== 1;
const hasDevelopmentSandboxes = getHasSandboxesByType(
accountConfig,
HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX
);
if (hasDevelopmentSandboxes) {
logger.error(
i18n(
`${i18nKey}.create.failure.alreadyInConfig.developer.${
plural ? 'other' : 'one'
}`,
{
accountName: uiAccountDescription(accountId),
limit: devSandboxLimit,
}
)
);
} else {
const baseUrl = getHubSpotWebsiteOrigin(getValidEnv(getEnv(accountId)));
logger.error(
i18n(
`${i18nKey}.create.failure.limit.developer.${
plural ? 'other' : 'one'
}`,
{
accountName: uiAccountDescription(accountId),
limit: devSandboxLimit,
link: `${baseUrl}/sandboxes-developer/${accountId}/development`,
}
)
);
}
logger.log('');
} else if (
isSpecifiedError(err, {
statusCode: 400,
category: 'VALIDATION_ERROR',
subCategory: 'SandboxErrors.NUM_STANDARD_SANDBOXES_LIMIT_EXCEEDED_ERROR',
}) &&
'error' in err &&
err.error instanceof Error
) {
logger.log('');
const standardSandboxLimit = getSandboxLimit(err.error);
const plural = standardSandboxLimit !== 1;
const hasStandardSandboxes = getHasSandboxesByType(
accountConfig,
HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX
);
if (hasStandardSandboxes) {
logger.error(
i18n(
`${i18nKey}.create.failure.alreadyInConfig.standard.${
plural ? 'other' : 'one'
}`,
{
accountName: uiAccountDescription(accountId),
limit: standardSandboxLimit,
}
)
);
} else {
const baseUrl = getHubSpotWebsiteOrigin(getValidEnv(getEnv(accountId)));
logger.error(
i18n(
`${i18nKey}.create.failure.limit.standard.${
plural ? 'other' : 'one'
}`,
{
accountName: uiAccountDescription(accountId),
limit: standardSandboxLimit,
link: `${baseUrl}/sandboxes-developer/${accountId}/standard`,
}
)
);
}
logger.log('');
} else {
logError(err);
}
Expand Down

0 comments on commit 3cbb2c0

Please sign in to comment.