From a2f5c70f6ff56155447086fc766b77064a4b15d9 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 20 Jan 2022 16:22:36 +0100 Subject: changes: Better error reporting --- modules/changes/changes.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'modules/changes') diff --git a/modules/changes/changes.js b/modules/changes/changes.js index f16c2ea..8851dbd 100644 --- a/modules/changes/changes.js +++ b/modules/changes/changes.js @@ -93,7 +93,7 @@ function fetch(method,url,data/*?*/,cb){ try { url=URL.parse(url); } catch(e){ - cb(-1,null); + cb(-1,"URL parse failed: "+e.message); return; } @@ -102,7 +102,7 @@ function fetch(method,url,data/*?*/,cb){ case "http:": httpclass=http; break; case "https:": httpclass=https; break; default: - cb(-1,null); + cb(-1,"Invalid URL protocol "+url.protocol); return; } @@ -114,16 +114,19 @@ function fetch(method,url,data/*?*/,cb){ body+=data; }); res.on("end",function(){ - if(!cbcalled)cb(res.statusCode,body); + if(!cbcalled){ + if(res.statusCode==-1)cb(-1,"negative status code"); + else cb(res.statusCode,body); + } cbcalled=true; }); res.on("error",function(err){ - if(!cbcalled)cb(-1,err); + if(!cbcalled)cb(-1,"response error: "+err); cbcalled=true; }); }); req.on("error",function(err){ - if(!cbcalled)cb(-1,err); + if(!cbcalled)cb(-1,"request error: "+err); cbcalled=true; }); if(data)req.write(data); @@ -142,7 +145,7 @@ function refreshURLs(cb){ nwaiting++; fetch("GET",url,function(url,status,body){ nwaiting--; - console.log("Got <"+url+">; status = "+status); + console.log("Got <"+url+">; status = "+status+(status==-1?" ("+body+")":"")); var dosave=true; if(status==-1){ hashes[url]=[new Date(),null,null]; -- cgit v1.2.3-54-g00ecf