refactor: errorsController func names

This commit is contained in:
Bobby Wibowo 2022-07-12 06:21:21 +07:00
parent 8267c60863
commit 7733967624
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
3 changed files with 8 additions and 8 deletions

View File

@ -11,7 +11,7 @@ const self = {
.map(key => Number(key))
}
self.handlerError = (req, res, error) => {
self.handleError = (req, res, error) => {
if (!res || res.headersSent) {
console.error('Unexpected missing "res" object or headers alredy sent.')
return console.trace()
@ -58,7 +58,7 @@ self.handlerError = (req, res, error) => {
}
}
self.handlerNotFound = (req, res) => {
self.handleNotFound = (req, res) => {
res.setHeader('Cache-Control', 'no-store')
return res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
}

View File

@ -41,6 +41,7 @@ const safe = new HyperExpress.Server({
trust_proxy: Boolean(config.trustProxy)
})
const errors = require('./controllers/errorsController')
const paths = require('./controllers/pathsController')
paths.initSync()
const utils = require('./controllers/utilsController')
@ -364,10 +365,9 @@ safe.use('/api', api)
}
}
// Web server error handlers (must always be set after all routes/routers)
const errorsController = require('./controllers/errorsController')
safe.set_not_found_handler(errorsController.handlerNotFound)
safe.set_error_handler(errorsController.handlerError)
// Web server error handlers (must always be set after all routes/middlewares)
safe.set_not_found_handler(errors.handleNotFound)
safe.set_error_handler(errors.handleError)
// Git hash
if (config.showGitHash) {

View File

@ -8,7 +8,7 @@ const config = require('./../config')
routes.get('/a/:identifier', async (req, res) => {
const identifier = req.params.identifier
if (identifier === undefined) {
return errors.handlerNotFound(req, res)
return errors.handleNotFound(req, res)
}
const album = await utils.db.table('albums')
@ -20,7 +20,7 @@ routes.get('/a/:identifier', async (req, res) => {
.first()
if (!album || album.public === 0) {
return errors.handlerNotFound(req, res)
return errors.handleNotFound(req, res)
}
const nojs = req.query.nojs !== undefined