feat: utilsController pass errors

This commit is contained in:
Bobby Wibowo 2022-07-10 14:15:14 +07:00
parent 99a7a2a677
commit 3a415165b4
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -9,7 +9,6 @@ const sharp = require('sharp')
const si = require('systeminformation')
const paths = require('./pathsController')
const perms = require('./permissionController')
const apiErrorsHandler = require('./handlers/apiErrorsHandler')
const ClientError = require('./utils/ClientError')
const ServerError = require('./utils/ServerError')
const SimpleDataStore = require('./utils/SimpleDataStore')
@ -785,8 +784,8 @@ self.invalidateStatsCache = type => {
statsData[type].cache = null
}
self.stats = async (req, res, next) => {
try {
self.stats = (req, res, next) => {
Promise.resolve().then(async () => {
const user = await self.authorize(req)
const isadmin = perms.is(user, 'admin')
@ -1092,13 +1091,13 @@ self.stats = async (req, res, next) => {
])
return res.json({ success: true, stats, hrtime: process.hrtime(hrstart) })
} catch (error) {
}).catch(error => {
// Reset generating state when encountering any errors
Object.keys(statsData).forEach(key => {
statsData[key].generating = false
})
return apiErrorsHandler(error, req, res, next)
}
return next(error)
})
}
module.exports = self