mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-01 21:30:30 +01:00
Update error handling
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user