anage errors

This commit is contained in:
Simon Martín 2018-08-01 15:32:44 +02:00
parent e9f88a78d5
commit bcad6dbe22

View File

@ -320,24 +320,29 @@ TemplateMaps.prototype.updTemplate = function(owner, tpl_id, template, callback)
self._redisCmd('HGET', [ userTemplatesKey, tpl_id ], (err, _currentTemplate) => {
assert.ifError(err);
if (!_currentTemplate) {
throw new Error("Template '" + tpl_id + "' of user '" + owner + "' does not exist");
if (err) {
return callback(err);
}
if (!_currentTemplate) {
return callback(new Error(`Template '${tpl_id}' of user '${owner}' does not exist`));
}
previousTemplate = _currentTemplate;
self._redisCmd('HSET', [ userTemplatesKey, templateName, JSON.stringify(template) ], (err, didSetNewField) => {
assert.ifError(err);
if (err) {
return callback(err);
}
if (didSetNewField) {
debug('New template created on update operation');
}
if (!err) {
if (self.fingerPrint(JSON.parse(previousTemplate)) !== self.fingerPrint(template)) {
self.emit('update', owner, templateName, template);
}
if (self.fingerPrint(JSON.parse(previousTemplate)) !== self.fingerPrint(template)) {
self.emit('update', owner, templateName, template);
}
callback(err, template);
return callback(err, template);
});
});
};