Skip to content

Commit 09a353f

Browse files
committed
refactor: change errorNotFound function signature to avoid parameter passing error
Signed-off-by: BoHong Li <[email protected]>
1 parent 6b1ce38 commit 09a353f

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ app.use(require('./lib/routes').router)
222222

223223
// response not found if no any route matxches
224224
app.get('*', function (req, res) {
225-
response.errorNotFound(res)
225+
response.errorNotFound(req, res)
226226
})
227227

228228
// socket.io secure

lib/history/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function historyGet (req, res) {
117117
if (req.isAuthenticated()) {
118118
getHistory(req.user.id, function (err, history) {
119119
if (err) return response.errorInternalError(res)
120-
if (!history) return response.errorNotFound(res)
120+
if (!history) return response.errorNotFound(req, res)
121121
res.send({
122122
history: parseHistoryToArray(history)
123123
})
@@ -150,8 +150,8 @@ function historyPost (req, res) {
150150
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(res)
151151
getHistory(req.user.id, function (err, history) {
152152
if (err) return response.errorInternalError(res)
153-
if (!history) return response.errorNotFound(res)
154-
if (!history[noteId]) return response.errorNotFound(res)
153+
if (!history) return response.errorNotFound(req, res)
154+
if (!history[noteId]) return response.errorNotFound(req, res)
155155
if (req.body.pinned === 'true' || req.body.pinned === 'false') {
156156
history[noteId].pinned = (req.body.pinned === 'true')
157157
setHistory(req.user.id, history, function (err, count) {
@@ -179,7 +179,7 @@ function historyDelete (req, res) {
179179
} else {
180180
getHistory(req.user.id, function (err, history) {
181181
if (err) return response.errorInternalError(res)
182-
if (!history) return response.errorNotFound(res)
182+
if (!history) return response.errorNotFound(req, res)
183183
delete history[noteId]
184184
setHistory(req.user.id, history, function (err, count) {
185185
if (err) return response.errorInternalError(res)

lib/note/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function showNote (req, res) {
6060
if (!note) {
6161
// if allow free url enable, auto create note
6262
if (!config.allowFreeURL || config.forbiddenNoteIDs.includes(noteId)) {
63-
return errorNotFound(res)
63+
return errorNotFound(req, res)
6464
}
6565
note = await createNote(userId, noteId)
6666
}
@@ -95,7 +95,7 @@ async function showPublishNote (req, res) {
9595
})
9696

9797
if (!note) {
98-
return errorNotFound(res)
98+
return errorNotFound(req, res)
9999
}
100100

101101
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {
@@ -146,7 +146,7 @@ async function noteActions (req, res) {
146146
const note = await getNoteById(noteId)
147147

148148
if (!note) {
149-
return errorNotFound(res)
149+
return errorNotFound(req, res)
150150
}
151151

152152
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {

lib/note/noteActions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ function actionRevision (req, res, note) {
173173
if (actionId) {
174174
const time = moment(parseInt(actionId))
175175
if (!time.isValid()) {
176-
return errorNotFound(res)
176+
return errorNotFound(req, res)
177177
}
178178
Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) {
179179
if (err) {
180180
logger.error(err)
181181
return errorInternalError(res)
182182
}
183183
if (!content) {
184-
return errorNotFound(res)
184+
return errorNotFound(req, res)
185185
}
186186
res.set({
187187
'Access-Control-Allow-Origin': '*', // allow CORS as API

lib/response.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function errorForbidden (req, res) {
3737
}
3838
}
3939

40-
function errorNotFound (res) {
40+
function errorNotFound (req, res) {
4141
responseError(res, '404', 'Not Found', 'oops.')
4242
}
4343

@@ -156,7 +156,7 @@ function findNote (req, res, callback, include) {
156156
req.alias = noteId
157157
return newNote(req, res)
158158
} else {
159-
return errorNotFound(res)
159+
return errorNotFound(req, res)
160160
}
161161
}
162162
if (!checkViewPermission(req, note)) {
@@ -313,7 +313,7 @@ function gitlabActionProjects (req, res, note) {
313313
id: req.user.id
314314
}
315315
}).then(function (user) {
316-
if (!user) { return errorNotFound(res) }
316+
if (!user) { return errorNotFound(req, res) }
317317
var ret = { baseURL: config.gitlab.baseURL, version: config.gitlab.version }
318318
ret.accesstoken = user.accessToken
319319
ret.profileid = user.profileid
@@ -351,7 +351,7 @@ function showPublishSlide (req, res, next) {
351351
if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) { return res.redirect(config.serverURL + '/p/' + (note.alias || note.shortid)) }
352352
note.increment('viewcount').then(function (note) {
353353
if (!note) {
354-
return errorNotFound(res)
354+
return errorNotFound(req, res)
355355
}
356356
var body = note.content
357357
var extracted = models.Note.extractMeta(body)

lib/user/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exports.getMe = async (req, res) => {
2323
})
2424

2525
if (!user) {
26-
return response.errorNotFound(res)
26+
return response.errorNotFound(req, res)
2727
}
2828
const profile = models.User.getProfile(user)
2929

@@ -47,7 +47,7 @@ exports.deleteUser = async (req, res) => {
4747
})
4848

4949
if (!user) {
50-
return response.errorNotFound(res)
50+
return response.errorNotFound(req, res)
5151
}
5252

5353
if (user.deleteToken !== req.params.token) {

0 commit comments

Comments
 (0)