mirror of https://github.com/status-im/codimd.git
refactor: change errorInternalError function signature to avoid parameter passing error
Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
parent
8787177991
commit
13ed2e6b44
|
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue