Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandbox error handling updates #990

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 3 additions & 1 deletion packages/cli/commands/project/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
const {
logApiErrorInstance,
ApiErrorContext,
isMissingScopeError,
isSpecifiedError,
} = require('../../lib/errorHandlers/apiErrors');
const {
isMissingScopeError,
} = require('@hubspot/local-dev-lib/errors/apiErrors');
Comment on lines +66 to +68
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I migrated over isMissingScopeError to the LDL version since its for a sandboxes endpoint, but left isSpecifiedError as the local version. The usage of isSpecifiedError in this file is for handleProjectUpload which is still pulling uploadProject from the old @hubspot/cli-lib dependency where the http base is still request-promise-native.

Same goes for cli -> lib -> projects.js in this repo since fetchProject is also pulled in from @hubspot/cli-lib. Usage is limited to just those two in projects files - I'll leave a comment in the code to reduce any confusion once that migration happens

const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');

const i18nKey = 'cli.commands.project.subcommands.dev';
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/commands/sandbox/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const {
const { promptUser } = require('../../lib/prompts/promptUtils');
const { syncSandbox } = require('../../lib/sandbox-sync');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const { isMissingScopeError } = require('../../lib/errorHandlers/apiErrors');
const {
isMissingScopeError,
} = require('@hubspot/local-dev-lib/errors/apiErrors');
const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');

const i18nKey = 'cli.commands.sandbox.subcommands.create';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/commands/sandbox/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
const {
isSpecifiedError,
isSpecifiedHubSpotAuthError,
} = require('../../lib/errorHandlers/apiErrors');
} = require('@hubspot/local-dev-lib/errors/apiErrors');
const { deleteSandbox } = require('@hubspot/local-dev-lib/sandboxes');
const { i18n } = require('../../lib/lang');
const { deleteSandboxPrompt } = require('../../lib/prompts/sandboxesPrompt');
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/commands/sandbox/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {
} = require('../../lib/sandboxes');
const { syncSandbox } = require('../../lib/sandbox-sync');
const { getValidEnv } = require('@hubspot/local-dev-lib/environment');
const { isSpecifiedError } = require('../../lib/errorHandlers/apiErrors');
const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/apiErrors');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');

const i18nKey = 'cli.commands.sandbox.subcommands.sync';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ en:
configFileUpdated: "{{ configFilename }} updated with {{ authMethod }} for account {{ account }}."
failure:
invalidUser: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because your account has been removed from {{#bold}}{{ parentAccountName }}{{/bold}} or your permission set doesn't allow you to create the sandbox. To update your permissions, contact a super admin in {{#bold}}{{ parentAccountName }}{{/bold}}."
403Gating: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because {{#bold}}{{ parentAccountName }}{{/bold}} does not have access to development sandboxes. To opt in to the CRM Development Beta and use development sandboxes, visit https://app.hubspot.com/l/whats-new/betas?productUpdateId=13860216."
limit:
developer:
one: "{{#bold}}{{ accountName }}{{/bold}} reached the limit of {{ limit }} development sandbox.
Expand Down
18 changes: 17 additions & 1 deletion packages/cli/lib/sandbox-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
const {
isMissingScopeError,
isSpecifiedError,
} = require('./errorHandlers/apiErrors');
} = require('@hubspot/local-dev-lib/errors/apiErrors');
const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
const { getEnv, getAccountId } = require('@hubspot/local-dev-lib/config');
const { createSandbox } = require('@hubspot/local-dev-lib/sandboxes');
Expand Down Expand Up @@ -101,6 +101,22 @@ const buildSandbox = async ({
})
);
logger.log('');
} else if (
isSpecifiedError(err, {
statusCode: 403,
category: 'BANNED',
subCategory: 'SandboxErrors.DEVELOPMENT_SANDBOX_ACCESS_NOT_ALLOWED',
Comment on lines +105 to +108
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a gating error scenario for when users are not ungated for crm-developement-beta

})
) {
logger.log('');
logger.error(
i18n(`${i18nKey}.failure.403Gating`, {
accountName: name,
parentAccountName: accountConfig.name || accountId,
accountId,
})
);
logger.log('');
} else if (
isSpecifiedError(err, {
statusCode: 400,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/sandbox-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
const {
isSpecifiedError,
isMissingScopeError,
} = require('./errorHandlers/apiErrors');
} = require('@hubspot/local-dev-lib/errors/apiErrors');
const { getSandboxTypeAsString } = require('./sandboxes');
const { getAccountId } = require('@hubspot/local-dev-lib/config');
const { uiAccountDescription } = require('./ui');
Expand Down
Loading