Commit b0c85dd9 by kevalbhatt

ATLAS-3629 : UI: skipDefaultError handler improvement

parent cd177f83
......@@ -258,7 +258,6 @@ require(['App',
}
});
this.entityDefCollection.fetch({
skipDefaultError: true,
complete: function() {
that.entityDefCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -269,7 +268,6 @@ require(['App',
}
});
this.typeHeaders.fetch({
skipDefaultError: true,
complete: function() {
that.typeHeaders.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -280,7 +278,6 @@ require(['App',
}
});
this.enumDefCollection.fetch({
skipDefaultError: true,
complete: function() {
that.enumDefCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -291,7 +288,6 @@ require(['App',
}
});
this.classificationDefCollection.fetch({
skipDefaultError: true,
complete: function() {
that.classificationDefCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -303,7 +299,6 @@ require(['App',
});
this.metricCollection.fetch({
skipDefaultError: true,
complete: function() {
--that.asyncFetchCounter;
startApp();
......
......@@ -34,7 +34,7 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
options.showLoader();
}
tagModel.deleteAssociation(options.guid, options.tagName, options.associatedGuid, {
skipDefaultError: true,
defaultErrorMessage: options.tagName + Messages.deleteErrorMessage,
success: function(data) {
Utils.notifySuccess({
content: "Classification " + options.tagName + Messages.getAbbreviationMsg(false, 'removeSuccessMessage')
......@@ -48,16 +48,9 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
},
cust_error: function(model, response) {
var message = options.tagName + Messages.deleteErrorMessage;
if (response && response.responseJSON) {
message = response.responseJSON.errorMessage;
}
if (options.hideLoader) {
options.hideLoader();
}
Utils.notifyError({
content: message
});
}
});
},
......
......@@ -37,9 +37,7 @@ define(['require', 'utils/Utils', 'marionette', 'backgrid', 'asBreadcrumbs', 'jq
return oldBackboneSync.apply(this, [method, model,
_.extend(options, {
error: function(response) {
if (!options.skipDefaultError) {
Utils.defaultErrorHandler(that, response);
}
Utils.defaultErrorHandler(that, response, options);
that.trigger("error", that, response);
if (options.cust_error) {
options.cust_error(that, response);
......
......@@ -218,22 +218,20 @@ define(['require', 'utils/Globals', 'pnotify', 'utils/Messages', 'utils/Enums',
}
});
}
Utils.defaultErrorHandler = function(model, error) {
Utils.defaultErrorHandler = function(model, error, options) {
var skipDefaultError = null,
defaultErrorMessage = null;
if (options) {
skipDefaultError = options.skipDefaultError;
defaultErrorMessage = options.defaultErrorMessage;
}
if (error && error.status) {
if (error.status == 401) {
window.location = 'login.jsp'
} else if (error.status == 419) {
window.location = 'login.jsp'
} else if (error.status == 403) {
var message = "You are not authorized";
if (error.statusText) {
try {
message = JSON.parse(error.statusText).AuthorizationError;
} catch (err) {}
Utils.notifyError({
content: message
});
}
Utils.serverErrorHandler(error, "You are not authorized");
} else if (error.status == "0" && error.statusText != "abort") {
var diffTime = (new Date().getTime() - prevNetworkErrorTime);
if (diffTime > 3000) {
......@@ -243,22 +241,23 @@ define(['require', 'utils/Globals', 'pnotify', 'utils/Messages', 'utils/Enums',
"It seems you are not connected to the internet. Please check your internet connection and try again"
});
}
} else {
Utils.serverErrorHandler(model, error)
} else if (skipDefaultError !== true) {
Utils.serverErrorHandler(error, defaultErrorMessage);
}
} else {
Utils.serverErrorHandler(model, error)
} else if (skipDefaultError !== true) {
Utils.serverErrorHandler(error, defaultErrorMessage);
}
};
Utils.serverErrorHandler = function(model, response) {
var responseJSON = response ? response.responseJSON : response;
if (response && responseJSON && (responseJSON.errorMessage || responseJSON.message || responseJSON.error)) {
Utils.notifyError({
content: responseJSON.errorMessage || responseJSON.message || responseJSON.error
});
} else {
Utils.serverErrorHandler = function(response, defaultErrorMessage) {
var responseJSON = response ? response.responseJSON : response,
message = defaultErrorMessage ? defaultErrorMessage : Messages.defaultErrorMessage
if (response && responseJSON) {
message = responseJSON.errorMessage || responseJSON.message || responseJSON.error || message
}
var existingError = $(".ui-pnotify-container.alert-danger .ui-pnotify-text").text();
if (existingError !== message) {
Utils.notifyError({
content: Messages.defaultErrorMessage
content: message
});
}
};
......
......@@ -225,7 +225,6 @@ define(['require',
"el": that.$(".graph-button-group button,select[data-id='selectDepth']")
});
this.collection.getLineage(this.guid, {
skipDefaultError: true,
queryParam: queryParam,
success: function(data) {
if (that.isDestroyed) {
......
......@@ -69,7 +69,6 @@ define(['require',
fetchEntity: function(argument) {
var that = this;
this.entityModel.getEntity(this.entityDetail.table.guid, {
skipDefaultError: true,
success: function(data) {
var entity = data.entity,
profileData = entity && entity.attributes && entity.attributes.profileData ? entity.attributes.profileData.attributes : null;
......
......@@ -110,7 +110,6 @@ define(['require',
fetchEntity: function(argument) {
var that = this;
this.entityModel.getEntity(this.entityDetail.db.guid, {
skipDefaultError: true,
success: function(data) {
var entity = data.entity;
if (entity.attributes) {
......
......@@ -381,7 +381,6 @@ define(['require',
}
};
this.metricCollection.fetch({
skipDefaultError: true,
complete: function() {
--apiCount;
that.entityCountObj = _.first(that.metricCollection.toJSON());
......@@ -390,7 +389,6 @@ define(['require',
});
this.typeHeaders.fetch({
skipDefaultError: true,
silent: true,
complete: function() {
--apiCount;
......
......@@ -104,7 +104,6 @@ define(['require',
fetchMetricData: function(options) {
var that = this;
this.metricCollection.fetch({
skipDefaultError: true,
success: function(data) {
var data = _.first(data.toJSON());
that.renderStats({ valueObject: data.general.stats, dataObject: data.general });
......
......@@ -439,9 +439,9 @@ define(['require',
this.showLoader();
}
this.entityModel.saveTraitsEntity(this.tagModel ? options.guid : null, {
skipDefaultError: true,
data: JSON.stringify(json),
type: this.tagModel ? 'PUT' : 'POST',
defaultErrorMessage: "Tag " + tagName + " could not be added",
success: function(data) {
var addupdatetext = that.tagModel ? 'updated successfully to ' : 'added to ';
Utils.notifySuccess({
......@@ -455,13 +455,6 @@ define(['require',
}
},
cust_error: function(model, response) {
var message = "Tag " + tagName + " could not be added";
if (response && response.responseJSON) {
message = response.responseJSON.errorMessage;
}
Utils.notifyError({
content: message
});
if (that.hideLoader) {
that.hideLoader();
}
......
......@@ -268,7 +268,6 @@ require(['App',
}
});
this.entityDefCollection.fetch({
skipDefaultError: true,
complete: function() {
that.entityDefCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -279,7 +278,6 @@ require(['App',
}
});
this.typeHeaders.fetch({
skipDefaultError: true,
complete: function() {
that.typeHeaders.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -290,7 +288,6 @@ require(['App',
}
});
this.enumDefCollection.fetch({
skipDefaultError: true,
complete: function() {
that.enumDefCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -301,7 +298,6 @@ require(['App',
}
});
this.classificationDefCollection.fetch({
skipDefaultError: true,
complete: function() {
that.classificationDefCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -313,7 +309,6 @@ require(['App',
});
this.metricCollection.fetch({
skipDefaultError: true,
complete: function() {
--that.asyncFetchCounter;
startApp();
......@@ -321,7 +316,6 @@ require(['App',
});
this.nameSpaceCollection.fetch({
skipDefaultError: true,
complete: function() {
that.nameSpaceCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......
......@@ -34,7 +34,7 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
options.showLoader();
}
tagModel.deleteAssociation(options.guid, options.tagName, options.associatedGuid, {
skipDefaultError: true,
defaultErrorMessage: options.tagName + Messages.deleteErrorMessage,
success: function(data) {
Utils.notifySuccess({
content: "Classification " + options.tagName + Messages.getAbbreviationMsg(false, 'removeSuccessMessage')
......@@ -48,16 +48,9 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
},
cust_error: function(model, response) {
var message = options.tagName + Messages.deleteErrorMessage;
if (response && response.responseJSON) {
message = response.responseJSON.errorMessage;
}
if (options.hideLoader) {
options.hideLoader();
}
Utils.notifyError({
content: message
});
}
});
},
......
......@@ -37,9 +37,7 @@ define(['require', 'utils/Utils', 'marionette', 'backgrid', 'asBreadcrumbs', 'jq
return oldBackboneSync.apply(this, [method, model,
_.extend(options, {
error: function(response) {
if (!options.skipDefaultError) {
Utils.defaultErrorHandler(that, response);
}
Utils.defaultErrorHandler(that, response, options);
that.trigger("error", that, response);
if (options.cust_error) {
options.cust_error(that, response);
......
......@@ -224,22 +224,20 @@ define(['require', 'utils/Globals', 'pnotify', 'utils/Messages', 'utils/Enums',
}
});
}
Utils.defaultErrorHandler = function(model, error) {
Utils.defaultErrorHandler = function(model, error, options) {
var skipDefaultError = null,
defaultErrorMessage = null;
if (options) {
skipDefaultError = options.skipDefaultError;
defaultErrorMessage = options.defaultErrorMessage;
}
if (error && error.status) {
if (error.status == 401) {
window.location = 'login.jsp'
} else if (error.status == 419) {
window.location = 'login.jsp'
} else if (error.status == 403) {
var message = "You are not authorized";
if (error.statusText) {
try {
message = JSON.parse(error.statusText).AuthorizationError;
} catch (err) {}
Utils.notifyError({
content: message
});
}
Utils.serverErrorHandler(error, "You are not authorized");
} else if (error.status == "0" && error.statusText != "abort") {
var diffTime = (new Date().getTime() - prevNetworkErrorTime);
if (diffTime > 3000) {
......@@ -249,22 +247,23 @@ define(['require', 'utils/Globals', 'pnotify', 'utils/Messages', 'utils/Enums',
"It seems you are not connected to the internet. Please check your internet connection and try again"
});
}
} else {
Utils.serverErrorHandler(model, error)
} else if (skipDefaultError !== true) {
Utils.serverErrorHandler(error, defaultErrorMessage);
}
} else {
Utils.serverErrorHandler(model, error)
} else if (skipDefaultError !== true) {
Utils.serverErrorHandler(error, defaultErrorMessage);
}
};
Utils.serverErrorHandler = function(model, response) {
var responseJSON = response ? response.responseJSON : response;
if (response && responseJSON && (responseJSON.errorMessage || responseJSON.message || responseJSON.error)) {
Utils.notifyError({
content: responseJSON.errorMessage || responseJSON.message || responseJSON.error
});
} else {
Utils.serverErrorHandler = function(response, defaultErrorMessage) {
var responseJSON = response ? response.responseJSON : response,
message = defaultErrorMessage ? defaultErrorMessage : Messages.defaultErrorMessage
if (response && responseJSON) {
message = responseJSON.errorMessage || responseJSON.message || responseJSON.error || message
}
var existingError = $(".ui-pnotify-container.alert-danger .ui-pnotify-text").text();
if (existingError !== message) {
Utils.notifyError({
content: Messages.defaultErrorMessage
content: message
});
}
};
......
......@@ -310,7 +310,6 @@ define(['require',
}
}
var apiObj = {
skipDefaultError: true,
sort: false,
success: function(dataOrCollection, response) {
if (!(that.ui.pageRecordText instanceof jQuery)) {
......
......@@ -240,7 +240,6 @@ define(['require',
"el": that.$(".graph-button-group button,select[data-id='selectDepth']")
});
this.collection.getLineage(this.guid, {
skipDefaultError: true,
queryParam: queryParam,
success: function(data) {
if (that.isDestroyed) {
......
......@@ -132,7 +132,6 @@ define(['require',
enumDefCollection.fetch({ reset: true });
that.nameSpaceAttr.fullCollection.reset();
that.options.selectedNameSpace.fetch({
skipDefaultError: true,
complete: function(model, status) {
that.nameSpaceAttr.fullCollection.add(model.responseJSON.attributeDefs);
}
......@@ -179,40 +178,40 @@ define(['require',
getNamespaceTableColumns: function() {
var that = this;
return this.nameSpaceAttr.constructor.getTableCols({
name: {
label: "Attribute Name",
cell: "html",
editable: false,
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function(rawValue, model) {
return model.get('name');
}
})
},
typeName: {
label: "typeName",
cell: "html",
editable: false,
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function(rawValue, model) {
return model.get('typeName');
}
})
},
options: {
label: "Entity Type(s)",
cell: "html",
editable: false,
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function(rawValue, model) {
var applicableEntityTypes = '',
attrEntityTypes = JSON.parse(model.get('options').applicableEntityTypes);
_.each(attrEntityTypes, function(values) {
applicableEntityTypes += '<label class="btn btn-action btn-xs btn-blue no-pointer">' + values + '</label>';
});
return applicableEntityTypes;
}
})
name: {
label: "Attribute Name",
cell: "html",
editable: false,
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function(rawValue, model) {
return model.get('name');
}
})
},
typeName: {
label: "typeName",
cell: "html",
editable: false,
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function(rawValue, model) {
return _.escape(model.get('typeName'));
}
})
},
options: {
label: "Entity Type(s)",
cell: "html",
editable: false,
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function(rawValue, model) {
var applicableEntityTypes = '',
attrEntityTypes = JSON.parse(model.get('options').applicableEntityTypes);
_.each(attrEntityTypes, function(values) {
applicableEntityTypes += '<label class="btn btn-action btn-xs btn-blue no-pointer">' + values + '</label>';
});
return applicableEntityTypes;
}
})
},
tool: {
label: "Action",
......@@ -226,7 +225,7 @@ define(['require',
})
}
}, this.nameSpaceAttr);
}
});
return NameSpaceAttrTableLayoutView;
}
});
return NameSpaceAttrTableLayoutView;
});
\ No newline at end of file
......@@ -69,7 +69,6 @@ define([
fetchNameSpaceGuid: function() {
var that = this;
this.selectedNameSpace.fetch({
skipDefaultError: true,
complete: function(model, status) {
that.nameSpaceAttr.fullCollection.add(model.responseJSON.attributeDefs);
}
......
......@@ -69,7 +69,6 @@ define(['require',
fetchEntity: function(argument) {
var that = this;
this.entityModel.getEntity(this.entityDetail.table.guid, {
skipDefaultError: true,
success: function(data) {
var entity = data.entity,
profileData = entity && entity.attributes && entity.attributes.profileData ? entity.attributes.profileData.attributes : null;
......
......@@ -110,7 +110,6 @@ define(['require',
fetchEntity: function(argument) {
var that = this;
this.entityModel.getEntity(this.entityDetail.db.guid, {
skipDefaultError: true,
success: function(data) {
var entity = data.entity;
if (entity.attributes) {
......
......@@ -174,7 +174,6 @@ define([
var opt = options || {};
if (opt && !opt.metricData) {
that.metricCollection.fetch({
skipDefaultError: true,
complete: function() {
that.entityCountObj = _.first(that.metricCollection.toJSON());
that.classificationTreeUpdate = true;
......@@ -351,7 +350,6 @@ define([
}
};
this.classificationDefCollection.fetch({
skipDefaultError: true,
silent: true,
complete: function() {
--apiCount;
......@@ -359,7 +357,6 @@ define([
}
});
this.metricCollection.fetch({
skipDefaultError: true,
complete: function() {
--apiCount;
that.entityCountObj = _.first(that.metricCollection.toJSON());
......
......@@ -91,7 +91,6 @@ define([
var opt = options || {};
if (opt && !opt.metricData) {
that.metricCollection.fetch({
skipDefaultError: true,
complete: function() {
that.entityCountObj = _.first(that.metricCollection.toJSON());
that.ui.entitySearchTree.jstree(true).refresh();
......@@ -510,7 +509,6 @@ define([
}
};
this.entityDefCollection.fetch({
skipDefaultError: true,
complete: function() {
that.entityDefCollection.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......@@ -522,7 +520,6 @@ define([
});
this.metricCollection.fetch({
skipDefaultError: true,
complete: function() {
--apiCount;
that.entityCountObj = _.first(that.metricCollection.toJSON());
......@@ -531,7 +528,6 @@ define([
});
this.typeHeaders.fetch({
skipDefaultError: true,
complete: function() {
that.typeHeaders.fullCollection.comparator = function(model) {
return model.get('name').toLowerCase();
......
......@@ -215,7 +215,6 @@ define([
refresh: function(options) {
var that = this;
this.nameSpaceCollection.fetch({
skipDefaultError: true,
silent: true,
complete: function() {
that.nameSpaceCollection.fullCollection.comparator = function(model) {
......
......@@ -99,7 +99,6 @@ define(['require',
fetchMetricData: function(options) {
var that = this;
this.metricCollection.fetch({
skipDefaultError: true,
success: function(data) {
var data = _.first(data.toJSON());
that.renderStats({ valueObject: data.general.stats, dataObject: data.general });
......
......@@ -439,9 +439,9 @@ define(['require',
this.showLoader();
}
this.entityModel.saveTraitsEntity(this.tagModel ? options.guid : null, {
skipDefaultError: true,
data: JSON.stringify(json),
type: this.tagModel ? 'PUT' : 'POST',
defaultErrorMessage: "Tag " + tagName + " could not be added",
success: function(data) {
var addupdatetext = that.tagModel ? 'updated successfully to ' : 'added to ';
Utils.notifySuccess({
......@@ -455,13 +455,6 @@ define(['require',
}
},
cust_error: function(model, response) {
var message = "Tag " + tagName + " could not be added";
if (response && response.responseJSON) {
message = response.responseJSON.errorMessage;
}
Utils.notifyError({
content: message
});
if (that.hideLoader) {
that.hideLoader();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment