Improve error handling for sports
parent
51783c5dec
commit
3f6251f5bb
|
@ -90,17 +90,25 @@ router.post('/season', checkLoginStatus.admin, async function(req, res, next) {
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/sport', checkLoginStatus.admin, function(req, res, next) {
|
router.get('/sport', checkLoginStatus.admin, function(req, res, next) {
|
||||||
res.render('manage/addsport', { title: 'Add Sport', userLoggedIn: !!req.user });
|
res.render('manage/addsport', { title: 'Add Sport', userLoggedIn: !!req.user, message: req.flash('error') });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/sport', checkLoginStatus.admin, function(req, res, next) {
|
router.post('/sport', checkLoginStatus.admin, async function(req, res, next) {
|
||||||
|
try {
|
||||||
const name = req.body['name'];
|
const name = req.body['name'];
|
||||||
const id = req.body['sport'];
|
const id = req.body['sport'];
|
||||||
const remove = req.body['remove'];
|
const remove = req.body['remove'];
|
||||||
|
|
||||||
if(remove) sports.remove(id).then(res.redirect('/manage'));
|
if(remove) await sports.remove(id);
|
||||||
else if(id) sports.rename(id, name).then(res.redirect('/manage'));
|
else if(id) await sports.rename(id, name);
|
||||||
else sports.add(name).then(res.redirect('/manage'));
|
else await sports.add(name);
|
||||||
|
|
||||||
|
res.redirect('/manage');
|
||||||
|
} catch(err) {
|
||||||
|
console.error("ERROR: " + err.message);
|
||||||
|
req.flash("error", "An error has occurred.");
|
||||||
|
res.redirect('/manage/sport');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/division', checkLoginStatus.admin, function(req, res, next) {
|
router.get('/division', checkLoginStatus.admin, function(req, res, next) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ block content
|
||||||
label Sport name
|
label Sport name
|
||||||
span(class='form-section-input')
|
span(class='form-section-input')
|
||||||
input#name-textbox(type="text" name="name" disabled)
|
input#name-textbox(type="text" name="name" disabled)
|
||||||
|
.error #{message}
|
||||||
span(class='form-section')
|
span(class='form-section')
|
||||||
button#submit-button(type="submit" disabled) Submit
|
button#submit-button(type="submit" disabled) Submit
|
||||||
span(class='form-section')
|
span(class='form-section')
|
||||||
|
|
Reference in New Issue