refactor: change errorNotFound 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:20:42 +08:00
parent 6b1ce381df
commit 09a353ffcc
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
6 changed files with 16 additions and 16 deletions

2
app.js
View File

@ -222,7 +222,7 @@ app.use(require('./lib/routes').router)
// response not found if no any route matxches
app.get('*', function (req, res) {
response.errorNotFound(res)
response.errorNotFound(req, res)
})
// socket.io secure

View File

@ -117,7 +117,7 @@ function historyGet (req, res) {
if (req.isAuthenticated()) {
getHistory(req.user.id, function (err, history) {
if (err) return response.errorInternalError(res)
if (!history) return response.errorNotFound(res)
if (!history) return response.errorNotFound(req, res)
res.send({
history: parseHistoryToArray(history)
})
@ -150,8 +150,8 @@ function historyPost (req, res) {
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(res)
getHistory(req.user.id, function (err, history) {
if (err) return response.errorInternalError(res)
if (!history) return response.errorNotFound(res)
if (!history[noteId]) return response.errorNotFound(res)
if (!history) return response.errorNotFound(req, res)
if (!history[noteId]) return response.errorNotFound(req, res)
if (req.body.pinned === 'true' || req.body.pinned === 'false') {
history[noteId].pinned = (req.body.pinned === 'true')
setHistory(req.user.id, history, function (err, count) {
@ -179,7 +179,7 @@ function historyDelete (req, res) {
} else {
getHistory(req.user.id, function (err, history) {
if (err) return response.errorInternalError(res)
if (!history) return response.errorNotFound(res)
if (!history) return response.errorNotFound(req, res)
delete history[noteId]
setHistory(req.user.id, history, function (err, count) {
if (err) return response.errorInternalError(res)

View File

@ -60,7 +60,7 @@ async function showNote (req, res) {
if (!note) {
// if allow free url enable, auto create note
if (!config.allowFreeURL || config.forbiddenNoteIDs.includes(noteId)) {
return errorNotFound(res)
return errorNotFound(req, res)
}
note = await createNote(userId, noteId)
}
@ -95,7 +95,7 @@ async function showPublishNote (req, res) {
})
if (!note) {
return errorNotFound(res)
return errorNotFound(req, res)
}
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {
@ -146,7 +146,7 @@ async function noteActions (req, res) {
const note = await getNoteById(noteId)
if (!note) {
return errorNotFound(res)
return errorNotFound(req, res)
}
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {

View File

@ -173,7 +173,7 @@ function actionRevision (req, res, note) {
if (actionId) {
const time = moment(parseInt(actionId))
if (!time.isValid()) {
return errorNotFound(res)
return errorNotFound(req, res)
}
Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) {
if (err) {
@ -181,7 +181,7 @@ function actionRevision (req, res, note) {
return errorInternalError(res)
}
if (!content) {
return errorNotFound(res)
return errorNotFound(req, res)
}
res.set({
'Access-Control-Allow-Origin': '*', // allow CORS as API

View File

@ -37,7 +37,7 @@ function errorForbidden (req, res) {
}
}
function errorNotFound (res) {
function errorNotFound (req, res) {
responseError(res, '404', 'Not Found', 'oops.')
}
@ -156,7 +156,7 @@ function findNote (req, res, callback, include) {
req.alias = noteId
return newNote(req, res)
} else {
return errorNotFound(res)
return errorNotFound(req, res)
}
}
if (!checkViewPermission(req, note)) {
@ -313,7 +313,7 @@ function gitlabActionProjects (req, res, note) {
id: req.user.id
}
}).then(function (user) {
if (!user) { return errorNotFound(res) }
if (!user) { return errorNotFound(req, res) }
var ret = { baseURL: config.gitlab.baseURL, version: config.gitlab.version }
ret.accesstoken = user.accessToken
ret.profileid = user.profileid
@ -351,7 +351,7 @@ function showPublishSlide (req, res, next) {
if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) { return res.redirect(config.serverURL + '/p/' + (note.alias || note.shortid)) }
note.increment('viewcount').then(function (note) {
if (!note) {
return errorNotFound(res)
return errorNotFound(req, res)
}
var body = note.content
var extracted = models.Note.extractMeta(body)

View File

@ -23,7 +23,7 @@ exports.getMe = async (req, res) => {
})
if (!user) {
return response.errorNotFound(res)
return response.errorNotFound(req, res)
}
const profile = models.User.getProfile(user)
@ -47,7 +47,7 @@ exports.deleteUser = async (req, res) => {
})
if (!user) {
return response.errorNotFound(res)
return response.errorNotFound(req, res)
}
if (user.deleteToken !== req.params.token) {