manage JSON parse and stringify sinc errors
This commit is contained in:
@@ -297,7 +297,6 @@ TemplateMaps.prototype.delTemplate = function(owner, tpl_id, callback) {
|
||||
// @param callback function(err)
|
||||
//
|
||||
TemplateMaps.prototype.updTemplate = function(owner, tpl_id, template, callback) {
|
||||
|
||||
template = templateDefaults(template);
|
||||
|
||||
var invalidError = this._checkInvalidTemplate(template);
|
||||
@@ -320,7 +319,14 @@ TemplateMaps.prototype.updTemplate = function(owner, tpl_id, template, callback)
|
||||
return callback(new Error(`Template '${tpl_id}' of user '${owner}' does not exist`));
|
||||
}
|
||||
|
||||
this._redisCmd('HSET', [userTemplatesKey, template.name, JSON.stringify(template)], (err, didSetNewField) => {
|
||||
let templateString;
|
||||
try {
|
||||
templateString = JSON.stringify(template)
|
||||
} catch (error) {
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
this._redisCmd('HSET', [userTemplatesKey, template.name, templateString], (err, didSetNewField) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -329,7 +335,14 @@ TemplateMaps.prototype.updTemplate = function(owner, tpl_id, template, callback)
|
||||
debug('New template created on update operation');
|
||||
}
|
||||
|
||||
if (this.fingerPrint(JSON.parse(beforeUpdateTemplate)) !== this.fingerPrint(template)) {
|
||||
let beforeUpdateTemplateObject;
|
||||
try {
|
||||
beforeUpdateTemplateObject = JSON.parse(beforeUpdateTemplate)
|
||||
} catch (error) {
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
if (this.fingerPrint(beforeUpdateTemplateObject) !== this.fingerPrint(template)) {
|
||||
this.emit('update', owner, template.name, template);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user