Skip to content

Commit

Permalink
Merge pull request #1354 from contentstack/bugfix/CS-44549
Browse files Browse the repository at this point in the history
CS-44549 - solved migration logger not adding the issue
  • Loading branch information
cs-raj authored Mar 26, 2024
2 parents ef8dfd0 + feccfed commit 188212a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/contentstack-migration/src/services/content-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const Base = require('../modules/base');
// Utils
const { map: _map, safePromise, successHandler, errorHandler, constants } = require('../utils');
const { map: _map, safePromise, successHandler, errorHandler, constants, errorHelper } = require('../utils');
// Map methods
const { get, getMapInstance, getDataWithAction } = _map;
const mapInstance = getMapInstance();
Expand All @@ -23,7 +23,7 @@ class ContentTypeService {

const [err, result] = await safePromise(this.stackSDKInstance.contentType(id).fetch());
if (err) {
errorHandler(id, ContentType, method, err);
errorHelper(err);
this.base.dispatch(callsite, id, err, 'apiError');
throw err;
}
Expand All @@ -36,7 +36,7 @@ class ContentTypeService {
const data = getDataWithAction(id, mapInstance, action);
const [err, result] = await safePromise(this.stackSDKInstance.contentType().create(data));
if (err) {
errorHandler(id, ContentType, 'POST', err);
errorHelper(err);
this.base.dispatch(callsite, id, err, 'apiError');
throw err;
}
Expand All @@ -51,7 +51,7 @@ class ContentTypeService {
const method = 'PUT';
const [err, result] = await safePromise(data.update());
if (err) {
errorHandler(data.uid, ContentType, method, err);
errorHelper(err);
this.base.dispatch(callsite, data.uid, err, 'apiError');
throw err;
}
Expand All @@ -66,7 +66,7 @@ class ContentTypeService {
const [err, result] = await safePromise(this.stackSDKInstance.contentType(id).delete());

if (err) {
errorHandler(id, ContentType, method, err);
errorHelper(err);
this.base.dispatch(callsite, id, err, 'apiError');
throw err;
}
Expand Down Expand Up @@ -306,7 +306,7 @@ class ContentTypeService {
}

// Handling both the scenarios
if ((found === 0) || (against && (found === 1))) {
if (found === 0 || (against && found === 1)) {
isValid = false;
}

Expand Down
9 changes: 8 additions & 1 deletion packages/contentstack-migration/src/utils/error-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ module.exports = (errors, filePath) => {
after = removeSpecialCharacter(after.join('\n'));
line = removeSpecialCharacter(line);
errorLogs[file].lines = { before, line, after };

if (error.request) {
error.data = error.request?.data;
delete error.request;
}
if (error.message) {
delete error.message;
}
const formattedCode = beforeLines + highlightedLine + afterLines;
if (error.payload?.apiError) {
errorLogs[file].apiError = true;
errorLogs[file].errorCode = error.payload.apiError.errorCode;
errorLogs[file].errors = error.payload.apiError.errors;
errorLogs[file].data = error.data;
}
if (error.message && !error.payload.apiError) {
errorLogs[file].apiError = false;
Expand Down

0 comments on commit 188212a

Please sign in to comment.