Skip to content

Commit 13ed2e6

Browse files
committed
refactor: change errorInternalError function signature to avoid parameter passing error
Signed-off-by: BoHong Li <[email protected]>
1 parent 8787177 commit 13ed2e6

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

lib/auth/email/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if (config.allowEmailRegister) {
5757
return res.redirect(config.serverURL + '/')
5858
}).catch(function (err) {
5959
logger.error('auth callback failed: ' + err)
60-
return response.errorInternalError(res)
60+
return response.errorInternalError(req, res)
6161
})
6262
})
6363
}

lib/history/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function parseHistoryToObject (history) {
116116
function historyGet (req, res) {
117117
if (req.isAuthenticated()) {
118118
getHistory(req.user.id, function (err, history) {
119-
if (err) return response.errorInternalError(res)
119+
if (err) return response.errorInternalError(req, res)
120120
if (!history) return response.errorNotFound(req, res)
121121
res.send({
122122
history: parseHistoryToArray(history)
@@ -140,7 +140,7 @@ function historyPost (req, res) {
140140
}
141141
if (Array.isArray(history)) {
142142
setHistory(req.user.id, history, function (err, count) {
143-
if (err) return response.errorInternalError(res)
143+
if (err) return response.errorInternalError(req, res)
144144
res.end()
145145
})
146146
} else {
@@ -149,13 +149,13 @@ function historyPost (req, res) {
149149
} else {
150150
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(req, res)
151151
getHistory(req.user.id, function (err, history) {
152-
if (err) return response.errorInternalError(res)
152+
if (err) return response.errorInternalError(req, res)
153153
if (!history) return response.errorNotFound(req, res)
154154
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) {
158-
if (err) return response.errorInternalError(res)
158+
if (err) return response.errorInternalError(req, res)
159159
res.end()
160160
})
161161
} else {
@@ -173,16 +173,16 @@ function historyDelete (req, res) {
173173
var noteId = req.params.noteId
174174
if (!noteId) {
175175
setHistory(req.user.id, [], function (err, count) {
176-
if (err) return response.errorInternalError(res)
176+
if (err) return response.errorInternalError(req, res)
177177
res.end()
178178
})
179179
} else {
180180
getHistory(req.user.id, function (err, history) {
181-
if (err) return response.errorInternalError(res)
181+
if (err) return response.errorInternalError(req, res)
182182
if (!history) return response.errorNotFound(req, res)
183183
delete history[noteId]
184184
setHistory(req.user.id, history, function (err, count) {
185-
if (err) return response.errorInternalError(res)
185+
if (err) return response.errorInternalError(req, res)
186186
res.end()
187187
})
188188
})

lib/note/noteActions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function actionPDF (req, res, note) {
8484
markdownpdf(markdownpdfOptions).from.string(content).to(pdfPath, function () {
8585
if (!fs.existsSync(pdfPath)) {
8686
logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + pdfPath)
87-
return errorInternalError(res)
87+
return errorInternalError(req, res)
8888
}
8989
const stream = fs.createReadStream(pdfPath)
9090
let filename = title
@@ -178,7 +178,7 @@ function actionRevision (req, res, note) {
178178
Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) {
179179
if (err) {
180180
logger.error(err)
181-
return errorInternalError(res)
181+
return errorInternalError(req, res)
182182
}
183183
if (!content) {
184184
return errorNotFound(req, res)
@@ -196,7 +196,7 @@ function actionRevision (req, res, note) {
196196
Revision.getNoteRevisions(note, function (err, data) {
197197
if (err) {
198198
logger.error(err)
199-
return errorInternalError(res)
199+
return errorInternalError(req, res)
200200
}
201201
const result = {
202202
revision: data

lib/response.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function errorTooLong (req, res) {
4949
responseError(res, '413', 'Payload Too Large', 'Shorten your note!')
5050
}
5151

52-
function errorInternalError (res) {
52+
function errorInternalError (req, res) {
5353
responseError(res, '500', 'Internal Error', 'wtf.')
5454
}
5555

@@ -113,7 +113,7 @@ function newNote (req, res, next) {
113113
return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id))
114114
}).catch(function (err) {
115115
logger.error(err)
116-
return errorInternalError(res)
116+
return errorInternalError(req, res)
117117
})
118118
}
119119

@@ -143,7 +143,7 @@ function findNote (req, res, callback, include) {
143143
models.Note.parseNoteId(id, function (err, _id) {
144144
if (err) {
145145
logger.error(err)
146-
return errorInternalError(res)
146+
return errorInternalError(req, res)
147147
}
148148
models.Note.findOne({
149149
where: {
@@ -166,7 +166,7 @@ function findNote (req, res, callback, include) {
166166
}
167167
}).catch(function (err) {
168168
logger.error(err)
169-
return errorInternalError(res)
169+
return errorInternalError(req, res)
170170
})
171171
})
172172
}
@@ -330,7 +330,7 @@ function gitlabActionProjects (req, res, note) {
330330
)
331331
}).catch(function (err) {
332332
logger.error('gitlab action projects failed: ' + err)
333-
return errorInternalError(res)
333+
return errorInternalError(req, res)
334334
})
335335
} else {
336336
return errorForbidden(req, res)
@@ -385,7 +385,7 @@ function showPublishSlide (req, res, next) {
385385
res.render('slide.ejs', data)
386386
}).catch(function (err) {
387387
logger.error(err)
388-
return errorInternalError(res)
388+
return errorInternalError(req, res)
389389
})
390390
}, include)
391391
}

lib/user/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ exports.exportMyData = (req, res) => {
7272
archive.pipe(res)
7373
archive.on('error', function (err) {
7474
logger.error('export user data failed: ' + err)
75-
return response.errorInternalError(res)
75+
return response.errorInternalError(req, res)
7676
})
7777

7878
models.User.findOne({
@@ -102,15 +102,15 @@ exports.exportMyData = (req, res) => {
102102
callback(null, null)
103103
}, function (err) {
104104
if (err) {
105-
return response.errorInternalError(res)
105+
return response.errorInternalError(req, res)
106106
}
107107

108108
archive.finalize()
109109
})
110110
})
111111
}).catch(function (err) {
112112
logger.error('export user data failed: ' + err)
113-
return response.errorInternalError(res)
113+
return response.errorInternalError(req, res)
114114
})
115115
}
116116

0 commit comments

Comments
 (0)