Update error handling

This commit is contained in:
André Zanghelini
2017-07-05 19:09:17 -03:00
parent 391aa6e67e
commit cdad5bf8c2
2 changed files with 12 additions and 20 deletions

View File

@@ -38,29 +38,20 @@ authenticationController.register = function (req, res) {
}
},
function (next) {
var err;
if (!userData.email) {
err = '[[error:invalid-email]]';
return next(new Error('[[error:invalid-email]]'));
}
if (!err && (!userData.username || userData.username.length < meta.config.minimumUsernameLength)) {
err = '[[error:username-too-short]]';
if (!userData.username || userData.username.length < meta.config.minimumUsernameLength) {
return next(new Error('[[error:username-too-short]]'));
}
if (!err && userData.username.length > meta.config.maximumUsernameLength) {
err = '[[error:username-too-long]]';
if (userData.username.length > meta.config.maximumUsernameLength) {
return next(new Error('[[error:username-too-long]]'));
}
if (!err && userData.password !== userData['password-confirm']) {
err = '[[user:change_password_error_match]]';
}
if (err) {
if (req.body.noscript === 'true') {
return helpers.noScriptErrors(req, res, err, 400);
}
return next(new Error(err));
if (userData.password !== userData['password-confirm']) {
return next(new Error('[[user:change_password_error_match]]'));
}
user.isPasswordValid(userData.password, next);
@@ -81,10 +72,7 @@ authenticationController.register = function (req, res) {
},
], function (err, data) {
if (err) {
if (req.body.noscript === 'true') {
return helpers.noScriptErrors(req, res, err.message, 400);
}
return res.status(400).send(err.message);
return helpers.noScriptErrors(req, res, err.message, 400);
}
if (data.uid && req.body.userLang) {

View File

@@ -15,6 +15,10 @@ var middleware = require('../middleware');
var helpers = module.exports;
helpers.noScriptErrors = function (req, res, error, httpStatus) {
if (req.body.noscript !== 'true') {
return res.status(httpStatus).send(error);
}
var middleware = require('../middleware');
var httpStatusString = httpStatus.toString();
middleware.buildHeader(req, res, function () {