1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Log error if settings unavailable when saving user settings

Fixes #1645
This commit is contained in:
Nick O'Leary 2018-04-16 15:02:28 +01:00
parent f4c2938b41
commit 52d9578a19
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 15 additions and 5 deletions

View File

@ -88,6 +88,7 @@ module.exports = {
} }
var currentSettings = settings.getUserSettings(username)||{}; var currentSettings = settings.getUserSettings(username)||{};
currentSettings = extend(currentSettings, req.body); currentSettings = extend(currentSettings, req.body);
try {
settings.setUserSettings(username, currentSettings).then(function() { settings.setUserSettings(username, currentSettings).then(function() {
log.audit({event: "settings.update",username:username},req); log.audit({event: "settings.update",username:username},req);
res.status(204).end(); res.status(204).end();
@ -95,6 +96,11 @@ module.exports = {
log.audit({event: "settings.update",username:username,error:err.code||"unexpected_error",message:err.toString()},req); log.audit({event: "settings.update",username:username,error:err.code||"unexpected_error",message:err.toString()},req);
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()}); res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
}); });
} catch(err) {
log.warn(log._("settings.user-not-available",{message:log._("settings.not-available")}));
log.audit({event: "settings.update",username:username,error:err.code||"unexpected_error",message:err.toString()},req);
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
}
} }
} }

View File

@ -75,6 +75,7 @@
}, },
"settings": { "settings": {
"user-not-available": "Cannot save user settings: __message__",
"not-available": "Settings not available", "not-available": "Settings not available",
"property-read-only": "Property '__prop__' is read-only" "property-read-only": "Property '__prop__' is read-only"
}, },

View File

@ -173,6 +173,9 @@ var persistentSettings = {
return clone(userSettings[username]); return clone(userSettings[username]);
}, },
setUserSettings: function(username,settings) { setUserSettings: function(username,settings) {
if (globalSettings === null) {
throw new Error(log._("settings.not-available"));
}
var current = userSettings[username]; var current = userSettings[username];
userSettings[username] = settings; userSettings[username] = settings;
try { try {