API: Properly handle not found cases for groups and characters

This commit is contained in:
2023-04-17 16:00:12 +02:00
parent 3915956bea
commit aea807ca3c
2 changed files with 2 additions and 2 deletions

View File

@@ -28,7 +28,7 @@ router.get('/characters', async (req, res) => {
router.get('/characters/:character_id', async (req, res) => { router.get('/characters/:character_id', async (req, res) => {
let character = await Character.findByPk(req.params.character_id); let character = await Character.findByPk(req.params.character_id);
if (!character.enabled && !isAuthorized(req)) { if (!character || !character.enabled && !isAuthorized(req)) {
res.status(404).json({ error: 'Character not found' }); res.status(404).json({ error: 'Character not found' });
return; return;
} }

View File

@@ -28,7 +28,7 @@ router.get('/groups', async (req, res) => {
router.get('/groups/:group_id', async (req, res) => { router.get('/groups/:group_id', async (req, res) => {
let group = await Group.findByPk(req.params.group_id); let group = await Group.findByPk(req.params.group_id);
if (!group.enabled && !isAuthorized(req)) { if (!group || !group.enabled && !isAuthorized(req)) {
res.status(404).json({ error: 'Group not found' }); res.status(404).json({ error: 'Group not found' });
return; return;
} }