Commit c4cafa68 authored by Thomas Urban's avatar Thomas Urban

revising error logging to cover every possible error while fetching

parent 3477948f
......@@ -131,7 +131,6 @@ class Client extends EventEmitter {
} );
if ( res.statusCode >= 400 ) {
this.logError( `ERROR: fetching URL ${url} failed with ${res.statusCode}` );
reject( Object.assign( new Error( `fetching URL ${url} failed with ${res.statusCode}` ), { httpStatus: res.statusCode } ) );
res.destroy();
return;
......@@ -145,7 +144,6 @@ class Client extends EventEmitter {
this.logInfo( `fetching URL ${url} redirects to ${location}` );
this.fetch( location ).then( resolve, reject );
} else {
this.logError( `ERROR: fetching URL ${url} resulted in redirect w/o target` );
reject( new Error( `fetching URL ${url} resulted in redirect w/o target` ) );
}
......@@ -155,8 +153,7 @@ class Client extends EventEmitter {
res.setTimeout( 20000 );
res.once( "error", error => {
this.logError( `ERROR: fetching URL ${url} failed: ${error}` );
reject( error );
reject( new Error( `fetching URL ${url} failed in response: ${error.message}` ) );
} );
res.once( "timeout", () => reject( new Error( `response from URL ${url} timed out` ) ) );
......@@ -176,7 +173,10 @@ class Client extends EventEmitter {
request.setTimeout( 20000 );
request.once( "error", reject );
request.once( "error", error => {
reject( new Error( `fetching URL ${url} failed in request: ${error.message}` ) );
} );
request.once( "timeout", () => reject( new Error( `request for URL ${url} timed out` ) ) );
request.end();
} )
......@@ -184,6 +184,7 @@ class Client extends EventEmitter {
this.updateStats( url, null, start );
return data;
}, error => {
this.logError( error.message );
this.updateStats( url, error.httpStatus || true, start );
throw error;
} );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment