a little error handling

This commit is contained in:
Martin Donnelly 2018-06-13 23:41:06 +01:00
parent 381d77ac64
commit dcbcd32e53

View File

@ -29,7 +29,7 @@ const cache = apicache.middleware;
const ips = ['212.71.255.44', '82.35.75.161'];
app.use(ipfilter(ips, { 'mode': 'allow' }));
// app.use(ipfilter(ips, { 'mode': 'allow' }));
app.use((err, req, res, _next) => {
console.log('Error handler', err);
@ -124,6 +124,7 @@ function getUrl (req, res) {
// console.log('Options', options);
logger.info(`>> getting ${theUrl}`);
function urlQuery (callback) {
const httpStart = RegExp('(http|ftp|https):\\/\\/');
try {
let count = 0;
http.request(options, responseHandler).end();
@ -141,11 +142,20 @@ function getUrl (req, res) {
logger.debug('>> follow', response.headers.location, count);
count++;
if (rUrl.protocol === 'https:')
https.request(rUrl, responseHandler).end();
else
http.request(rUrl, responseHandler).end();
if (!httpStart.test(response.headers.location)) {
//
logger.warn('response.headers.location is not a valid url...');
logger.info(`Failed to follow for ${theUrl}`);
logger.warn(response.headers.location);
logger.debug(response.headers);
}
else {
count++;
if (rUrl.protocol === 'https:')
https.request(rUrl, responseHandler).end();
else
http.request(rUrl, responseHandler).end();
}
}
let data = '';