Skip to content

Commit

Permalink
Remove cli-lib/errorHandlers from other CLI packages
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Oct 16, 2023
1 parent 2cc9160 commit edd4818
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/cli/lib/prompts/projectsLogsPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { getProjectConfig, ensureProjectExists } = require('../projects');
const {
logApiErrorInstance,
ApiErrorContext,
} = require('@hubspot/cli-lib/errorHandlers');
} = require('../../lib/errorHandlers/apiErrors');
const { logger } = require('@hubspot/cli-lib/logger');
const { EXIT_CODES } = require('../enums/exitCodes');

Expand Down
7 changes: 3 additions & 4 deletions packages/serverless-dev-runtime/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ const bodyParser = require('body-parser');
const cors = require('cors');
const chalk = require('chalk');
const { logger, setLogLevel, LOG_LEVEL } = require('@hubspot/cli-lib/logger');
const {
logErrorInstance,
} = require('@hubspot/cli-lib/errorHandlers/standardErrors');
const {
getTableContents,
getTableHeader,
Expand Down Expand Up @@ -181,7 +178,9 @@ const startServer = async callback => {
},
};
} catch (e) {
logErrorInstance(e, {
logger.error(`A system error has occurred: ${e.message}`);
logger.debug(e);
logger.debug({
port,
accountId,
functionPath,
Expand Down
66 changes: 54 additions & 12 deletions packages/webpack-cms-plugins/HubSpotAutoUploadPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ const {
getAccountId,
checkAndWarnGitInclusion,
} = require('@hubspot/cli-lib');
const {
ApiErrorContext,
logApiUploadErrorInstance,
} = require('@hubspot/cli-lib/errorHandlers');
const { logger } = require('@hubspot/cli-lib/logger');
const { isAllowedExtension } = require('@hubspot/cli-lib/path');
const {
LOG_LEVEL,
Expand All @@ -22,6 +19,41 @@ checkAndWarnGitInclusion(getConfigPath());

const pluginName = 'HubSpotAutoUploadPlugin';

const parseValidationErrors = (responseBody = {}) => {
const errorMessages = [];

const { errors, message } = responseBody;

if (message) {
errorMessages.push(message);
}

if (errors) {
const specificErrors = errors.map(error => {
let errorMessage = error.message;
if (error.errorTokens && error.errorTokens.line) {
errorMessage = `line ${error.errorTokens.line}: ${errorMessage}`;
}
return errorMessage;
});
errorMessages.push(...specificErrors);
}

return errorMessages;
};

function logValidationErrors(error, context) {
const { response = {} } = error;
const validationErrors = parseValidationErrors(response.body);
if (validationErrors.length) {
validationErrors.forEach(err => {
logger.error(err);
});
}
logger.debug(error);
logger.debug(context);
}

class HubSpotAutoUploadPlugin {
constructor(options = {}) {
const { src, dest, portal, account, autoupload } = options;
Expand Down Expand Up @@ -67,14 +99,24 @@ class HubSpotAutoUploadPlugin {
})
.catch(error => {
webpackLogger.error(`Uploading ${dest} failed`);
logApiUploadErrorInstance(
error,
new ApiErrorContext({
accountId: this.accountId,
request: dest,
payload: filepath,
})
);
const context = {
accountId: this.accountId,
request: dest,
payload: filepath,
statusCode: error.statusCode,
};
if (
error.statusCode === 400 &&
error.response &&
error.response.body &&
(error.response.body.message || error.response.body.errors)
) {
logValidationErrors(error, context);
} else {
console.error(error.message);
console.debug(error);
console.debug(context);
}
});
});
});
Expand Down

0 comments on commit edd4818

Please sign in to comment.