mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
refactor: errorsController func names
This commit is contained in:
parent
8267c60863
commit
7733967624
@ -11,7 +11,7 @@ const self = {
|
|||||||
.map(key => Number(key))
|
.map(key => Number(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
self.handlerError = (req, res, error) => {
|
self.handleError = (req, res, error) => {
|
||||||
if (!res || res.headersSent) {
|
if (!res || res.headersSent) {
|
||||||
console.error('Unexpected missing "res" object or headers alredy sent.')
|
console.error('Unexpected missing "res" object or headers alredy sent.')
|
||||||
return console.trace()
|
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')
|
res.setHeader('Cache-Control', 'no-store')
|
||||||
return res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
|
return res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ const safe = new HyperExpress.Server({
|
|||||||
trust_proxy: Boolean(config.trustProxy)
|
trust_proxy: Boolean(config.trustProxy)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const errors = require('./controllers/errorsController')
|
||||||
const paths = require('./controllers/pathsController')
|
const paths = require('./controllers/pathsController')
|
||||||
paths.initSync()
|
paths.initSync()
|
||||||
const utils = require('./controllers/utilsController')
|
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)
|
// Web server error handlers (must always be set after all routes/middlewares)
|
||||||
const errorsController = require('./controllers/errorsController')
|
safe.set_not_found_handler(errors.handleNotFound)
|
||||||
safe.set_not_found_handler(errorsController.handlerNotFound)
|
safe.set_error_handler(errors.handleError)
|
||||||
safe.set_error_handler(errorsController.handlerError)
|
|
||||||
|
|
||||||
// Git hash
|
// Git hash
|
||||||
if (config.showGitHash) {
|
if (config.showGitHash) {
|
||||||
|
@ -8,7 +8,7 @@ const config = require('./../config')
|
|||||||
routes.get('/a/:identifier', async (req, res) => {
|
routes.get('/a/:identifier', async (req, res) => {
|
||||||
const identifier = req.params.identifier
|
const identifier = req.params.identifier
|
||||||
if (identifier === undefined) {
|
if (identifier === undefined) {
|
||||||
return errors.handlerNotFound(req, res)
|
return errors.handleNotFound(req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
const album = await utils.db.table('albums')
|
const album = await utils.db.table('albums')
|
||||||
@ -20,7 +20,7 @@ routes.get('/a/:identifier', async (req, res) => {
|
|||||||
.first()
|
.first()
|
||||||
|
|
||||||
if (!album || album.public === 0) {
|
if (!album || album.public === 0) {
|
||||||
return errors.handlerNotFound(req, res)
|
return errors.handleNotFound(req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
const nojs = req.query.nojs !== undefined
|
const nojs = req.query.nojs !== undefined
|
||||||
|
Loading…
Reference in New Issue
Block a user