summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2022-01-20 16:22:36 +0100
committerTom Smeding <tom@tomsmeding.com>2022-01-20 16:22:36 +0100
commita2f5c70f6ff56155447086fc766b77064a4b15d9 (patch)
treea9a4854eef49a9d890318b3f1742a4a689cb6fd8
parentcf73352be30f37df19025971aac545e50934b774 (diff)
changes: Better error reporting
-rw-r--r--modules/changes/changes.js15
1 files changed, 9 insertions, 6 deletions
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];