refactor: change errorBadRequest function signature to avoid parameter passing error

Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
BoHong Li 2020-02-26 11:22:59 +08:00
parent 09a353ffcc
commit 35a2135b36
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
5 changed files with 12 additions and 12 deletions

View File

@ -33,8 +33,8 @@ passport.use(new LocalStrategy({
if (config.allowEmailRegister) {
emailAuth.post('/register', urlencodedParser, function (req, res, next) {
if (!req.body.email || !req.body.password) return response.errorBadRequest(res)
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(res)
if (!req.body.email || !req.body.password) return response.errorBadRequest(req, res)
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(req, res)
models.User.findOrCreate({
where: {
email: req.body.email
@ -63,8 +63,8 @@ if (config.allowEmailRegister) {
}
emailAuth.post('/login', urlencodedParser, function (req, res, next) {
if (!req.body.email || !req.body.password) return response.errorBadRequest(res)
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(res)
if (!req.body.email || !req.body.password) return response.errorBadRequest(req, res)
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(req, res)
setReturnToFromReferer(req)
passport.authenticate('local', {
successReturnToOrRedirect: config.serverURL + '/',

View File

@ -81,7 +81,7 @@ passport.use(new LDAPStrategy({
}))
ldapAuth.post('/auth/ldap', urlencodedParser, function (req, res, next) {
if (!req.body.username || !req.body.password) return response.errorBadRequest(res)
if (!req.body.username || !req.body.password) return response.errorBadRequest(req, res)
setReturnToFromReferer(req)
passport.authenticate('ldapauth', {
successReturnToOrRedirect: config.serverURL + '/',

View File

@ -131,12 +131,12 @@ function historyPost (req, res) {
if (req.isAuthenticated()) {
var noteId = req.params.noteId
if (!noteId) {
if (typeof req.body['history'] === 'undefined') return response.errorBadRequest(res)
if (typeof req.body['history'] === 'undefined') return response.errorBadRequest(req, res)
if (config.debug) { logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history) }
try {
var history = JSON.parse(req.body.history)
} catch (err) {
return response.errorBadRequest(res)
return response.errorBadRequest(req, res)
}
if (Array.isArray(history)) {
setHistory(req.user.id, history, function (err, count) {
@ -144,10 +144,10 @@ function historyPost (req, res) {
res.end()
})
} else {
return response.errorBadRequest(res)
return response.errorBadRequest(req, res)
}
} else {
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(res)
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(req, res)
getHistory(req.user.id, function (err, history) {
if (err) return response.errorInternalError(res)
if (!history) return response.errorNotFound(req, res)
@ -159,7 +159,7 @@ function historyPost (req, res) {
res.end()
})
} else {
return response.errorBadRequest(res)
return response.errorBadRequest(req, res)
}
})
}

View File

@ -8,7 +8,7 @@ module.exports = function (req, res, next) {
decodeURIComponent(req.path)
} catch (err) {
logger.error(err)
return response.errorBadRequest(res)
return response.errorBadRequest(req, res)
}
next()
}

View File

@ -41,7 +41,7 @@ function errorNotFound (req, res) {
responseError(res, '404', 'Not Found', 'oops.')
}
function errorBadRequest (res) {
function errorBadRequest (req, res) {
responseError(res, '400', 'Bad Request', 'something not right.')
}