diff --git a/src/controllers/api/account/logoutController.js b/src/controllers/api/account/logoutController.js index 515c272..3e2132c 100644 --- a/src/controllers/api/account/logoutController.js +++ b/src/controllers/api/account/logoutController.js @@ -16,6 +16,7 @@ along with this program. If not, see .*/ //local imports const accountUtils = require('../../../utils/sessionUtils.js'); +const {exceptionHandler} = require('../../../utils/loggerUtils.js'); module.exports.get = async function(req, res){ if(req.session.user){ @@ -23,8 +24,7 @@ module.exports.get = async function(req, res){ accountUtils.killSession(req.session); return res.sendStatus(200); }catch(err){ - res.status(400); - return res.send(err.message) + return exceptionHandler(res, err); } }else{ res.status(400); diff --git a/src/controllers/api/admin/listChannelsController.js b/src/controllers/api/admin/listChannelsController.js index 0e64cd6..138a42d 100644 --- a/src/controllers/api/admin/listChannelsController.js +++ b/src/controllers/api/admin/listChannelsController.js @@ -15,7 +15,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ //local imports -const channelModel = require('../../../schemas/channelSchema'); +const {exceptionHandler} = require('../../../utils/loggerUtils.js'); +const channelModel = require('../../../schemas/channelSchema.js'); //api account functions module.exports.get = async function(req, res){ @@ -25,7 +26,6 @@ module.exports.get = async function(req, res){ res.status(200); return res.send(chanGuide); }catch(err){ - res.status(400); - return res.send(err.message); + return exceptionHandler(res, err); } } \ No newline at end of file diff --git a/src/controllers/api/admin/listUsersController.js b/src/controllers/api/admin/listUsersController.js index 6de55d4..624a957 100644 --- a/src/controllers/api/admin/listUsersController.js +++ b/src/controllers/api/admin/listUsersController.js @@ -15,6 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ //local imports +const {exceptionHandler} = require('../../../utils/loggerUtils.js'); const userModel = require('../../../schemas/userSchema'); //api account functions @@ -25,7 +26,6 @@ module.exports.get = async function(req, res){ res.status(200); return res.send(userList); }catch(err){ - res.status(400); - return res.send(err.message); + return exceptionHandler(res, err); } } \ No newline at end of file diff --git a/src/controllers/api/channel/listController.js b/src/controllers/api/channel/listController.js index 8474561..fe28a3c 100644 --- a/src/controllers/api/channel/listController.js +++ b/src/controllers/api/channel/listController.js @@ -16,6 +16,7 @@ along with this program. If not, see .*/ //local imports const channelModel = require('../../../schemas/channelSchema'); +const {exceptionHandler} = require('../../../utils/loggerUtils.js'); //api account functions module.exports.get = async function(req, res){ @@ -25,7 +26,6 @@ module.exports.get = async function(req, res){ res.status(200); return res.send(chanGuide); }catch(err){ - res.status(400); - return res.send(err.message); + return exceptionHandler(res, err); } } \ No newline at end of file diff --git a/src/controllers/channelSettingsController.js b/src/controllers/channelSettingsController.js index de1fedd..3520373 100644 --- a/src/controllers/channelSettingsController.js +++ b/src/controllers/channelSettingsController.js @@ -16,6 +16,9 @@ along with this program. If not, see .*/ //Config const config = require('../../config.json'); + +//local imports +const {exceptionHandler} = require('../utils/loggerUtils.js'); const channelModel = require('../schemas/channelSchema'); //root index functions @@ -30,7 +33,6 @@ module.exports.get = async function(req, res){ return res.render('channelSettings', {instance: config.instanceName, user: req.session.user, channel}); }catch(err){ - res.status(500); - res.send(err.message); + return exceptionHandler(res, err); } } \ No newline at end of file diff --git a/src/controllers/indexController.js b/src/controllers/indexController.js index d8439fd..1edc763 100644 --- a/src/controllers/indexController.js +++ b/src/controllers/indexController.js @@ -16,6 +16,9 @@ along with this program. If not, see .*/ //Config const config = require('../../config.json'); + +//local imports +const {exceptionHandler} = require('../utils/loggerUtils.js'); const channelModel = require('../schemas/channelSchema'); //root index functions @@ -24,7 +27,6 @@ module.exports.get = async function(req, res){ const chanGuide = await channelModel.getChannelList(); return res.render('index', {instance: config.instanceName, user: req.session.user, chanGuide: chanGuide}); }catch(err){ - res.status(500); - return res.send("Error indexing channels!"); + return exceptionHandler(res, err); } } \ No newline at end of file diff --git a/src/controllers/profileController.js b/src/controllers/profileController.js index 48a884b..c6248c6 100644 --- a/src/controllers/profileController.js +++ b/src/controllers/profileController.js @@ -16,6 +16,7 @@ along with this program. If not, see .*/ //Local Imports const userModel = require('../schemas/userSchema'); +const {exceptionHandler} = require('../utils/loggerUtils.js'); //Config const config = require('../../config.json'); @@ -23,28 +24,31 @@ const config = require('../../config.json'); //profile functions module.exports.get = async function(req, res){ + try{ + var profileName = req.url.slice(1) == '' ? (req.session.user ? req.session.user.user : null) : req.url.slice(1); - var profileName = req.url.slice(1) == '' ? (req.session.user ? req.session.user.user : null) : req.url.slice(1); + const userDB = await userModel.findOne({ user: profileName }); - const userDB = await userModel.findOne({ user: profileName }); - - if(userDB){ - res.render('profile', {instance: config.instanceName, - user: req.session.user, - profile: { - id: userDB.id, - user: userDB.user, - date: userDB.date, - tokes: userDB.tokes, - img: userDB.img, - signature: userDB.signature, - bio: userDB.bio - } - }); - }else{ - res.render('profile', {instance: config.instanceName, - user: req.session.user, - profile: null - }); + if(userDB){ + res.render('profile', {instance: config.instanceName, + user: req.session.user, + profile: { + id: userDB.id, + user: userDB.user, + date: userDB.date, + tokes: userDB.tokes, + img: userDB.img, + signature: userDB.signature, + bio: userDB.bio + } + }); + }else{ + res.render('profile', {instance: config.instanceName, + user: req.session.user, + profile: null + }); + } + }catch(err){ + return exceptionHandler(res, err); } } \ No newline at end of file