From 13ed2e6b44e8fc61e5a07edad2eb8917d1ee8b7e Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Wed, 26 Feb 2020 11:26:01 +0800 Subject: [PATCH] refactor: change errorInternalError function signature to avoid parameter passing error Signed-off-by: BoHong Li --- lib/auth/email/index.js | 2 +- lib/history/index.js | 14 +++++++------- lib/note/noteActions.js | 6 +++--- lib/response.js | 12 ++++++------ lib/user/index.js | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/auth/email/index.js b/lib/auth/email/index.js index 4c130b9f..5c748745 100644 --- a/lib/auth/email/index.js +++ b/lib/auth/email/index.js @@ -57,7 +57,7 @@ if (config.allowEmailRegister) { return res.redirect(config.serverURL + '/') }).catch(function (err) { logger.error('auth callback failed: ' + err) - return response.errorInternalError(res) + return response.errorInternalError(req, res) }) }) } diff --git a/lib/history/index.js b/lib/history/index.js index 139bd9f7..3826ce98 100644 --- a/lib/history/index.js +++ b/lib/history/index.js @@ -116,7 +116,7 @@ function parseHistoryToObject (history) { function historyGet (req, res) { if (req.isAuthenticated()) { getHistory(req.user.id, function (err, history) { - if (err) return response.errorInternalError(res) + if (err) return response.errorInternalError(req, res) if (!history) return response.errorNotFound(req, res) res.send({ history: parseHistoryToArray(history) @@ -140,7 +140,7 @@ function historyPost (req, res) { } if (Array.isArray(history)) { setHistory(req.user.id, history, function (err, count) { - if (err) return response.errorInternalError(res) + if (err) return response.errorInternalError(req, res) res.end() }) } else { @@ -149,13 +149,13 @@ function historyPost (req, res) { } else { 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 (err) return response.errorInternalError(req, 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) { - if (err) return response.errorInternalError(res) + if (err) return response.errorInternalError(req, res) res.end() }) } else { @@ -173,16 +173,16 @@ function historyDelete (req, res) { var noteId = req.params.noteId if (!noteId) { setHistory(req.user.id, [], function (err, count) { - if (err) return response.errorInternalError(res) + if (err) return response.errorInternalError(req, res) res.end() }) } else { getHistory(req.user.id, function (err, history) { - if (err) return response.errorInternalError(res) + if (err) return response.errorInternalError(req, 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) + if (err) return response.errorInternalError(req, res) res.end() }) }) diff --git a/lib/note/noteActions.js b/lib/note/noteActions.js index 19ea3b65..90f23f69 100644 --- a/lib/note/noteActions.js +++ b/lib/note/noteActions.js @@ -84,7 +84,7 @@ function actionPDF (req, res, note) { markdownpdf(markdownpdfOptions).from.string(content).to(pdfPath, function () { if (!fs.existsSync(pdfPath)) { logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + pdfPath) - return errorInternalError(res) + return errorInternalError(req, res) } const stream = fs.createReadStream(pdfPath) let filename = title @@ -178,7 +178,7 @@ function actionRevision (req, res, note) { Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) { if (err) { logger.error(err) - return errorInternalError(res) + return errorInternalError(req, res) } if (!content) { return errorNotFound(req, res) @@ -196,7 +196,7 @@ function actionRevision (req, res, note) { Revision.getNoteRevisions(note, function (err, data) { if (err) { logger.error(err) - return errorInternalError(res) + return errorInternalError(req, res) } const result = { revision: data diff --git a/lib/response.js b/lib/response.js index 1e681558..3e9cb891 100644 --- a/lib/response.js +++ b/lib/response.js @@ -49,7 +49,7 @@ function errorTooLong (req, res) { responseError(res, '413', 'Payload Too Large', 'Shorten your note!') } -function errorInternalError (res) { +function errorInternalError (req, res) { responseError(res, '500', 'Internal Error', 'wtf.') } @@ -113,7 +113,7 @@ function newNote (req, res, next) { return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id)) }).catch(function (err) { logger.error(err) - return errorInternalError(res) + return errorInternalError(req, res) }) } @@ -143,7 +143,7 @@ function findNote (req, res, callback, include) { models.Note.parseNoteId(id, function (err, _id) { if (err) { logger.error(err) - return errorInternalError(res) + return errorInternalError(req, res) } models.Note.findOne({ where: { @@ -166,7 +166,7 @@ function findNote (req, res, callback, include) { } }).catch(function (err) { logger.error(err) - return errorInternalError(res) + return errorInternalError(req, res) }) }) } @@ -330,7 +330,7 @@ function gitlabActionProjects (req, res, note) { ) }).catch(function (err) { logger.error('gitlab action projects failed: ' + err) - return errorInternalError(res) + return errorInternalError(req, res) }) } else { return errorForbidden(req, res) @@ -385,7 +385,7 @@ function showPublishSlide (req, res, next) { res.render('slide.ejs', data) }).catch(function (err) { logger.error(err) - return errorInternalError(res) + return errorInternalError(req, res) }) }, include) } diff --git a/lib/user/index.js b/lib/user/index.js index 979be7af..c0687282 100644 --- a/lib/user/index.js +++ b/lib/user/index.js @@ -72,7 +72,7 @@ exports.exportMyData = (req, res) => { archive.pipe(res) archive.on('error', function (err) { logger.error('export user data failed: ' + err) - return response.errorInternalError(res) + return response.errorInternalError(req, res) }) models.User.findOne({ @@ -102,7 +102,7 @@ exports.exportMyData = (req, res) => { callback(null, null) }, function (err) { if (err) { - return response.errorInternalError(res) + return response.errorInternalError(req, res) } archive.finalize() @@ -110,7 +110,7 @@ exports.exportMyData = (req, res) => { }) }).catch(function (err) { logger.error('export user data failed: ' + err) - return response.errorInternalError(res) + return response.errorInternalError(req, res) }) }