Added some error logging to the server

This commit is contained in:
Martin Donnelly 2020-01-20 23:15:01 +00:00
parent fcae12997d
commit 960427c906

View File

@ -19,6 +19,9 @@ const sitePath = 'live';
apicache.options({ 'debug': true }); apicache.options({ 'debug': true });
const cache = apicache.middleware; const cache = apicache.middleware;
const standardError = {
'error':'There was an error'
};
app.use(express.static(path.join(__dirname, sitePath))); app.use(express.static(path.join(__dirname, sitePath)));
@ -39,7 +42,7 @@ app.get('/weather', (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'weather', 'e':e }));
}); });
else { else {
@ -60,7 +63,7 @@ app.get('/forecast', (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'forecast', 'e':e }));
}); });
else { else {
@ -80,7 +83,7 @@ app.get('/weatheralert', cache('15 minutes'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'weatheralert', 'e':e }));
}); });
else { else {
@ -103,7 +106,7 @@ app.get('/fsexplore', cache('15 minutes'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'fsexplore', 'e':e }));
}); });
} }
@ -124,7 +127,7 @@ app.get('/geocode', /*cache('15 minutes'),*/ (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'geocode', 'e':e }));
}); });
} }
@ -135,7 +138,6 @@ app.get('/geocode', /*cache('15 minutes'),*/ (req, res) => {
} }
}); });
app.get('/rightbyme', cache('86400 seconds'), (req, res) => { app.get('/rightbyme', cache('86400 seconds'), (req, res) => {
if (req.query.hasOwnProperty('ll')) if (req.query.hasOwnProperty('ll'))
rightbyme.doGetRightByMe(req.query.ll) rightbyme.doGetRightByMe(req.query.ll)
@ -144,7 +146,7 @@ app.get('/rightbyme', cache('86400 seconds'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'rightbyme', 'e':e }));
}); });
else { else {
@ -162,7 +164,7 @@ app.get('/nearbydetail', cache('15 minutes'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'nearbydetail', 'e':e }));
}); });
else { else {
@ -183,7 +185,7 @@ app.get('/news', cache('15 minutes'), (req, res) => {
} }
else { else {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'news', 'e':e }));
} }
}); });
}); });
@ -198,7 +200,7 @@ app.get('/article', cache('1 hour'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'article', 'e':e }));
}); });
} }
else { else {
@ -215,7 +217,7 @@ app.get('/agenda', cache('15 minutes'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'agenda', 'e':e }));
}); });
}); });
@ -229,7 +231,7 @@ app.get('/oldtraffic', cache('5 minutes'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'oldtraffic', 'e':e }));
}); });
else { else {
@ -248,7 +250,7 @@ app.get('/incidents', cache('5 minutes'), (req, res) => {
res.send(d); res.send(d);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('directions.getIncidents: There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'incidents', 'e':e }));
}); });
}); });
@ -263,7 +265,7 @@ app.get('/traffic', cache('5 minutes'), asyncMiddleware(async (req, res, next) =
res.send(b); res.send(b);
}).catch((e) => { }).catch((e) => {
logger.error(e); logger.error(e);
res.status(500).send('There was an error!'); res.status(500).send(Object.assign(standardError, { 'source':'traffic', 'e':e }));
}); });
else { else {