refactor: change errorInternalError 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:26:01 +08:00
parent 8787177991
commit 13ed2e6b44
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
5 changed files with 20 additions and 20 deletions

View File

@ -57,7 +57,7 @@ if (config.allowEmailRegister) {
return res.redirect(config.serverURL + '/') return res.redirect(config.serverURL + '/')
}).catch(function (err) { }).catch(function (err) {
logger.error('auth callback failed: ' + err) logger.error('auth callback failed: ' + err)
return response.errorInternalError(res) return response.errorInternalError(req, res)
}) })
}) })
} }

View File

@ -116,7 +116,7 @@ function parseHistoryToObject (history) {
function historyGet (req, res) { function historyGet (req, res) {
if (req.isAuthenticated()) { if (req.isAuthenticated()) {
getHistory(req.user.id, function (err, history) { 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) return response.errorNotFound(req, res)
res.send({ res.send({
history: parseHistoryToArray(history) history: parseHistoryToArray(history)
@ -140,7 +140,7 @@ function historyPost (req, res) {
} }
if (Array.isArray(history)) { if (Array.isArray(history)) {
setHistory(req.user.id, history, function (err, count) { setHistory(req.user.id, history, function (err, count) {
if (err) return response.errorInternalError(res) if (err) return response.errorInternalError(req, res)
res.end() res.end()
}) })
} else { } else {
@ -149,13 +149,13 @@ function historyPost (req, res) {
} else { } else {
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(req, res) if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(req, res)
getHistory(req.user.id, function (err, history) { 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) return response.errorNotFound(req, res)
if (!history[noteId]) return response.errorNotFound(req, res) if (!history[noteId]) return response.errorNotFound(req, res)
if (req.body.pinned === 'true' || req.body.pinned === 'false') { if (req.body.pinned === 'true' || req.body.pinned === 'false') {
history[noteId].pinned = (req.body.pinned === 'true') history[noteId].pinned = (req.body.pinned === 'true')
setHistory(req.user.id, history, function (err, count) { setHistory(req.user.id, history, function (err, count) {
if (err) return response.errorInternalError(res) if (err) return response.errorInternalError(req, res)
res.end() res.end()
}) })
} else { } else {
@ -173,16 +173,16 @@ function historyDelete (req, res) {
var noteId = req.params.noteId var noteId = req.params.noteId
if (!noteId) { if (!noteId) {
setHistory(req.user.id, [], function (err, count) { setHistory(req.user.id, [], function (err, count) {
if (err) return response.errorInternalError(res) if (err) return response.errorInternalError(req, res)
res.end() res.end()
}) })
} else { } else {
getHistory(req.user.id, function (err, history) { 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) return response.errorNotFound(req, res)
delete history[noteId] delete history[noteId]
setHistory(req.user.id, history, function (err, count) { setHistory(req.user.id, history, function (err, count) {
if (err) return response.errorInternalError(res) if (err) return response.errorInternalError(req, res)
res.end() res.end()
}) })
}) })

View File

@ -84,7 +84,7 @@ function actionPDF (req, res, note) {
markdownpdf(markdownpdfOptions).from.string(content).to(pdfPath, function () { markdownpdf(markdownpdfOptions).from.string(content).to(pdfPath, function () {
if (!fs.existsSync(pdfPath)) { if (!fs.existsSync(pdfPath)) {
logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + 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) const stream = fs.createReadStream(pdfPath)
let filename = title let filename = title
@ -178,7 +178,7 @@ function actionRevision (req, res, note) {
Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) { Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) {
if (err) { if (err) {
logger.error(err) logger.error(err)
return errorInternalError(res) return errorInternalError(req, res)
} }
if (!content) { if (!content) {
return errorNotFound(req, res) return errorNotFound(req, res)
@ -196,7 +196,7 @@ function actionRevision (req, res, note) {
Revision.getNoteRevisions(note, function (err, data) { Revision.getNoteRevisions(note, function (err, data) {
if (err) { if (err) {
logger.error(err) logger.error(err)
return errorInternalError(res) return errorInternalError(req, res)
} }
const result = { const result = {
revision: data revision: data

View File

@ -49,7 +49,7 @@ function errorTooLong (req, res) {
responseError(res, '413', 'Payload Too Large', 'Shorten your note!') responseError(res, '413', 'Payload Too Large', 'Shorten your note!')
} }
function errorInternalError (res) { function errorInternalError (req, res) {
responseError(res, '500', 'Internal Error', 'wtf.') 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)) return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id))
}).catch(function (err) { }).catch(function (err) {
logger.error(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) { models.Note.parseNoteId(id, function (err, _id) {
if (err) { if (err) {
logger.error(err) logger.error(err)
return errorInternalError(res) return errorInternalError(req, res)
} }
models.Note.findOne({ models.Note.findOne({
where: { where: {
@ -166,7 +166,7 @@ function findNote (req, res, callback, include) {
} }
}).catch(function (err) { }).catch(function (err) {
logger.error(err) logger.error(err)
return errorInternalError(res) return errorInternalError(req, res)
}) })
}) })
} }
@ -330,7 +330,7 @@ function gitlabActionProjects (req, res, note) {
) )
}).catch(function (err) { }).catch(function (err) {
logger.error('gitlab action projects failed: ' + err) logger.error('gitlab action projects failed: ' + err)
return errorInternalError(res) return errorInternalError(req, res)
}) })
} else { } else {
return errorForbidden(req, res) return errorForbidden(req, res)
@ -385,7 +385,7 @@ function showPublishSlide (req, res, next) {
res.render('slide.ejs', data) res.render('slide.ejs', data)
}).catch(function (err) { }).catch(function (err) {
logger.error(err) logger.error(err)
return errorInternalError(res) return errorInternalError(req, res)
}) })
}, include) }, include)
} }

View File

@ -72,7 +72,7 @@ exports.exportMyData = (req, res) => {
archive.pipe(res) archive.pipe(res)
archive.on('error', function (err) { archive.on('error', function (err) {
logger.error('export user data failed: ' + err) logger.error('export user data failed: ' + err)
return response.errorInternalError(res) return response.errorInternalError(req, res)
}) })
models.User.findOne({ models.User.findOne({
@ -102,7 +102,7 @@ exports.exportMyData = (req, res) => {
callback(null, null) callback(null, null)
}, function (err) { }, function (err) {
if (err) { if (err) {
return response.errorInternalError(res) return response.errorInternalError(req, res)
} }
archive.finalize() archive.finalize()
@ -110,7 +110,7 @@ exports.exportMyData = (req, res) => {
}) })
}).catch(function (err) { }).catch(function (err) {
logger.error('export user data failed: ' + err) logger.error('export user data failed: ' + err)
return response.errorInternalError(res) return response.errorInternalError(req, res)
}) })
} }