From 0ac58dbee68481715fe60ec89f1fee4b9a1917e5 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 9 Apr 2014 21:56:30 -0400 Subject: [PATCH] more error strings --- public/language/en_GB/error.json | 10 ++++++- src/categories.js | 4 +-- src/controllers/accounts.js | 4 +-- src/controllers/categories.js | 4 +-- src/controllers/topics.js | 4 +-- src/groups.js | 50 +++++++++++++++++--------------- 6 files changed, 44 insertions(+), 32 deletions(-) diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index d0fd0f31e0..c60dfa0692 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -6,12 +6,16 @@ "invalid-cid": "Invalid Category ID", "invalid-tid": "Invalid Topic ID", "invalid-pid": "Invalid Post ID", + "invalid-uid": "Invalid User ID", "no-category": "Category doesn't exist", "no-topic": "Topic doesn't exist", "no-post": "Post doesn't exist", + "no-group": "Group doesn't exist", "no-privileges": "You don't have enough privileges for this action.", + "category-disabled": "Category disabled", + "topic-locked": "Topic Locked", "still-uploading" : "Please wait for uploads to complete.", @@ -27,5 +31,9 @@ "cant-ban-other-admins": "You can't ban other admins!", - "invalid-image-type": "Invalid image type" + "invalid-image-type": "Invalid image type", + + "group-name-too-short": "Group name too short", + "group-already-exists": "Group already exists", + "group-name-change-not-allowed": "Group name change not allowed" } \ No newline at end of file diff --git a/src/categories.js b/src/categories.js index 809c77c8e5..409e8e7aeb 100644 --- a/src/categories.js +++ b/src/categories.js @@ -64,7 +64,7 @@ var db = require('./database'), Categories.getCategoryById = function(cid, start, end, uid, callback) { Categories.getCategoryData(cid, function(err, category) { if(err || !category) { - return callback(err || new Error('category-not-found [' + cid + ']')); + return callback(err || new Error('[[error:invalid-cid]]')); } if(parseInt(uid, 10)) { @@ -278,7 +278,7 @@ var db = require('./database'), Categories.getCategories = function(cids, uid, callback) { if (!Array.isArray(cids) || cids.length === 0) { - return callback(new Error('invalid-cids')); + return callback(new Error('[[error:invalid-cid]]')); } async.parallel({ diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 369449e9aa..518c170445 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -33,7 +33,7 @@ function userNotAllowed(res) { function getUserDataByUserSlug(userslug, callerUID, callback) { user.getUidByUserslug(userslug, function(err, uid) { if(err || !uid) { - return callback(err || new Error('invalid-user')); + return callback(err || new Error('[[error:invalid-uid]]')); } async.parallel({ @@ -54,7 +54,7 @@ function getUserDataByUserSlug(userslug, callerUID, callback) { } }, function(err, results) { if(err || !results.userData) { - return callback(err || new Error('invalid-user')); + return callback(err || new Error('[[error:invalid-uid]]')); } var userData = results.userData; diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 93112a2524..f30dcc13b3 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -70,7 +70,7 @@ categoriesController.get = function(req, res, next) { categoryTools.privileges(cid, uid, function(err, categoryPrivileges) { if (!err) { if (!categoryPrivileges.read) { - next(new Error('not-enough-privileges')); + next(new Error('[[error:no-privileges]]')); } else { next(null, categoryPrivileges); } @@ -95,7 +95,7 @@ categoriesController.get = function(req, res, next) { if (categoryData) { if (parseInt(categoryData.disabled, 10) === 1) { - return next(new Error('Category disabled'), null); + return next(new Error('[[error:category-disabled]]')); } } diff --git a/src/controllers/topics.js b/src/controllers/topics.js index aa5488295d..5fdf606d47 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -26,7 +26,7 @@ topicsController.get = function(req, res, next) { } if (!userPrivileges.read) { - return next(new Error('not-enough-privileges')); + return next(new Error('[[error:no-privileges]]')); } privileges = userPrivileges; @@ -45,7 +45,7 @@ topicsController.get = function(req, res, next) { topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) { if (topicData) { if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) { - return next(new Error('Topic deleted')); + return next(new Error('[[error:no-topic]]')); } topicData.currentPage = page; } diff --git a/src/groups.js b/src/groups.js index 24894ff7fb..6501b3dc66 100644 --- a/src/groups.js +++ b/src/groups.js @@ -137,7 +137,7 @@ Groups.create = function(name, description, callback) { if (name.length === 0) { - return callback(new Error('name-too-short')); + return callback(new Error('[[error:group-name-too-short]]')); } if (name === 'administrators' || name === 'registered-users') { @@ -145,28 +145,32 @@ } Groups.exists(name, function (err, exists) { - if (!exists) { - var groupData = { - name: name, - description: description, - deleted: '0', - hidden: '0', - system: system ? '1' : '0' - }; + if (err) { + return callback(err); + } - async.parallel([ - function(next) { - db.setAdd('groups', name, next); - }, - function(next) { - db.setObject('group:' + name, groupData, function(err) { - Groups.get(name, {}, next); - }); - } - ], callback); - } else { - callback(new Error('group-exists')); + if (exists) { + return callback(new Error('[[error:group-already-exists]]')); } + + var groupData = { + name: name, + description: description, + deleted: '0', + hidden: '0', + system: system ? '1' : '0' + }; + + async.parallel([ + function(next) { + db.setAdd('groups', name, next); + }, + function(next) { + db.setObject('group:' + name, groupData, function(err) { + Groups.get(name, {}, next); + }); + } + ], callback); }); }; @@ -184,12 +188,12 @@ db.setObject('group:' + groupName, values, callback); } else { if (callback) { - callback(new Error('name-change-not-allowed')); + callback(new Error('[[error:group-name-change-not-allowed]]')); } } } else { if (callback) { - callback(new Error('gid-not-found')); + callback(new Error('[[error:no-group]]')); } } });