diff --git a/src/messaging.js b/src/messaging.js index 7609ad24f9..0631de61f8 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -374,12 +374,8 @@ var db = require('./database'), }; Messaging.canMessage = function(fromUid, toUid, callback) { - if (parseInt(meta.config.disableChat) === 1) { - return callback(new Error('[[error:chat-disabled]]')); - } else if (toUid === fromUid) { - return callback(new Error('[[error:cant-chat-with-yourself]]')); - } else if (!fromUid) { - return callback(new Error('[[error:not-logged-in]]')); + if (parseInt(meta.config.disableChat) === 1 || !fromUid || toUid === fromUid) { + return callback(null, false); } async.waterfall([ @@ -388,17 +384,17 @@ var db = require('./database'), }, function (exists, next) { if (!exists) { - return next(new Error('[[error:no-user]]')); + return callback(null, false); } user.getUserFields(fromUid, ['banned', 'email:confirmed'], next); }, function (userData, next) { if (parseInt(userData.banned, 10) === 1) { - return next(new Error('[[error:user-banned]]')); + return callback(null, false); } if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) { - return next(new Error('[[error:email-not-confirmed-chat]]')); + return callback(null, false); } user.getSettings(toUid, next); diff --git a/src/routes/index.js b/src/routes/index.js index 57a8c8134a..8d011f7f5a 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -175,7 +175,7 @@ function handle404(app, middleware) { } function handleErrors(app, middleware) { - app.use(function(err, req, res) { + app.use(function(err, req, res, next) { if (err.code === 'EBADCSRFTOKEN') { winston.error(req.path + '\n', err.message); return res.sendStatus(403); @@ -190,7 +190,7 @@ function handleErrors(app, middleware) { res.status(err.status || 500); if (res.locals.isAPI) { - return res.json({path: req.path, error: err.message}); + res.json({path: req.path, error: err.message}); } else { middleware.buildHeader(req, res, function() { res.render('500', {path: req.path, error: err.message}); diff --git a/src/views/500-embed.tpl b/src/views/500-embed.tpl new file mode 100644 index 0000000000..537cbac136 --- /dev/null +++ b/src/views/500-embed.tpl @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/src/views/500.tpl b/src/views/500.tpl index 537cbac136..3abb9e8e27 100644 --- a/src/views/500.tpl +++ b/src/views/500.tpl @@ -1,9 +1,6 @@ - \ No newline at end of file