Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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