basic erro r handling for 404 sites
This commit is contained in:
parent
effc4db088
commit
7d09bfafb3
@ -4,9 +4,12 @@ module.exports = {
|
|||||||
// Find site by ID export
|
// Find site by ID export
|
||||||
findById: function(req, res){
|
findById: function(req, res){
|
||||||
Site.findById(req.params.id, function(err, site){
|
Site.findById(req.params.id, function(err, site){
|
||||||
if(err) throw err;
|
// if(err) throw err;
|
||||||
|
if(err) res.render('index', { title: 'Site is not found!'});
|
||||||
|
else {
|
||||||
console.log("Site->Controller: findById queried: " + site.site);
|
console.log("Site->Controller: findById queried: " + site.site);
|
||||||
res.render('site', { title: site.site, site: site });
|
res.render('site', { title: site.site, site: site });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,12 @@ Site.findById = function(id, callback){
|
|||||||
|
|
||||||
con.query(sql, id, function(err, result){
|
con.query(sql, id, function(err, result){
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
// if not site is found.
|
||||||
|
if (result[0] == undefined) callback(404);
|
||||||
|
else {
|
||||||
console.log("Site.findById: " + result[0].site + " retrieved!");
|
console.log("Site.findById: " + result[0].site + " retrieved!");
|
||||||
callback(err, new Site(result[0]));
|
callback(err, new Site(result[0]));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user